mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-06 05:39:12 +00:00
Stop OpenAI chat from emitting reference notes directly in chat body
The Chat models sometime output reference notes directly in the chat body in unformatted form, specifically as Notes:\n['. Prevent that. Reference notes are shown in clean, formatted form anyway
This commit is contained in:
@@ -134,4 +134,5 @@ def converse(
|
|||||||
temperature=temperature,
|
temperature=temperature,
|
||||||
openai_api_key=api_key,
|
openai_api_key=api_key,
|
||||||
completion_func=completion_func,
|
completion_func=completion_func,
|
||||||
|
model_kwargs={"stop": ["Notes:\n["]},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -69,15 +69,15 @@ def completion_with_backoff(**kwargs):
|
|||||||
reraise=True,
|
reraise=True,
|
||||||
)
|
)
|
||||||
def chat_completion_with_backoff(
|
def chat_completion_with_backoff(
|
||||||
messages, compiled_references, model_name, temperature, openai_api_key=None, completion_func=None
|
messages, compiled_references, model_name, temperature, openai_api_key=None, completion_func=None, model_kwargs=None
|
||||||
):
|
):
|
||||||
g = ThreadedGenerator(compiled_references, completion_func=completion_func)
|
g = ThreadedGenerator(compiled_references, completion_func=completion_func)
|
||||||
t = Thread(target=llm_thread, args=(g, messages, model_name, temperature, openai_api_key))
|
t = Thread(target=llm_thread, args=(g, messages, model_name, temperature, openai_api_key, model_kwargs))
|
||||||
t.start()
|
t.start()
|
||||||
return g
|
return g
|
||||||
|
|
||||||
|
|
||||||
def llm_thread(g, messages, model_name, temperature, openai_api_key=None):
|
def llm_thread(g, messages, model_name, temperature, openai_api_key=None, model_kwargs=None):
|
||||||
callback_handler = StreamingChatCallbackHandler(g)
|
callback_handler = StreamingChatCallbackHandler(g)
|
||||||
chat = ChatOpenAI(
|
chat = ChatOpenAI(
|
||||||
streaming=True,
|
streaming=True,
|
||||||
@@ -86,6 +86,7 @@ def llm_thread(g, messages, model_name, temperature, openai_api_key=None):
|
|||||||
model_name=model_name, # type: ignore
|
model_name=model_name, # type: ignore
|
||||||
temperature=temperature,
|
temperature=temperature,
|
||||||
openai_api_key=openai_api_key or os.getenv("OPENAI_API_KEY"),
|
openai_api_key=openai_api_key or os.getenv("OPENAI_API_KEY"),
|
||||||
|
model_kwargs=model_kwargs,
|
||||||
request_timeout=20,
|
request_timeout=20,
|
||||||
max_retries=1,
|
max_retries=1,
|
||||||
client=None,
|
client=None,
|
||||||
|
|||||||
Reference in New Issue
Block a user