bots can talk to each other

This commit is contained in:
2026-03-10 12:48:33 -04:00
parent 2a55c412d2
commit d063519c04
2 changed files with 132 additions and 0 deletions

View File

@@ -44,6 +44,41 @@ def chat_completion(
return ""
def chat_completion_with_history(
system_prompt: str,
prompts: Iterable[ChatCompletionMessageParam],
openai_url: str,
openai_api_key: str,
model: str,
max_tokens: int = 1000,
) -> str:
client = openai.OpenAI(base_url=openai_url, api_key=openai_api_key)
messages: Iterable[ChatCompletionMessageParam] = [
{
"role": "system",
"content": system_prompt,
}
] + prompts # type: ignore
response = client.chat.completions.create(
model=model,
messages=messages,
max_tokens=max_tokens,
extra_body={
"chat_template_kwargs": {"enable_thinking": False},
},
)
# Assert that thinking was used
if response.choices[0].message.model_extra:
assert response.choices[0].message.model_extra.get("reasoning_content")
content = response.choices[0].message.content
if content:
return content.strip()
else:
return ""
def chat_completion_instruct(
system_prompt: str,
user_prompt: str,