diff --git a/app/config.py b/app/config.py index f596d58d..24c2b8ec 100644 --- a/app/config.py +++ b/app/config.py @@ -1,9 +1,27 @@ import os +import types from guidance.llms import OpenAI +import guidance.llms._openai from pyaml_env import parse_config from pydantic import BaseModel, validator, Field, typing +old_add_text_to_chat_mode = guidance.llms._openai.add_text_to_chat_mode + + +def new_add_text_to_chat_mode(chat_mode): + if isinstance(chat_mode, (types.AsyncGeneratorType, types.GeneratorType)): + print("new_add_text_to_chat_mode", chat_mode) + return guidance.llms._openai.add_text_to_chat_mode_generator(chat_mode) + else: + print("new_add_text_to_chat_mode", chat_mode.items()) + for c in chat_mode["choices"]: + c["text"] = c["message"]["content"] + return chat_mode + + +guidance.llms._openai.add_text_to_chat_mode = new_add_text_to_chat_mode + class LLMModelSpecs(BaseModel): context_length: int diff --git a/app/services/circuit_breaker.py b/app/services/circuit_breaker.py index d5b1e342..fb080c1c 100644 --- a/app/services/circuit_breaker.py +++ b/app/services/circuit_breaker.py @@ -135,5 +135,7 @@ def get_status(cls, checkhealth_func, cache_key: str): ) return cls.Status.CLOSED - cache_store.set(status_key, cls.Status.OPEN, ex=cls.OPEN_TTL_SECONDS) + cache_store.set( + status_key, cls.Status.OPEN, ex=cls.OPEN_TTL_SECONDS + ) return cls.Status.OPEN