From c4898bf3075c7b8b90975119b2c38356e73e3eaf Mon Sep 17 00:00:00 2001 From: zachary62 Date: Tue, 13 May 2025 16:16:39 -0400 Subject: [PATCH] implement nodes and flows --- .../pocketflow-voice-chat/utils/call_llm.py | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/cookbook/pocketflow-voice-chat/utils/call_llm.py b/cookbook/pocketflow-voice-chat/utils/call_llm.py index 830185e..1b70b63 100644 --- a/cookbook/pocketflow-voice-chat/utils/call_llm.py +++ b/cookbook/pocketflow-voice-chat/utils/call_llm.py @@ -1,30 +1,20 @@ -import os from openai import OpenAI +import os -def call_llm(prompt, history=None): +def call_llm(messages): client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY", "your-api-key")) - - messages = [] - if history: - messages.extend(history) - messages.append({"role": "user", "content": prompt}) - - r = client.chat.completions.create( + + response = client.chat.completions.create( model="gpt-4o", - messages=messages + messages=messages, + temperature=0.7 ) - return r.choices[0].message.content + + return response.choices[0].message.content if __name__ == "__main__": - print("Testing LLM call...") - - response = call_llm("Tell me a short joke") - print(f"LLM (Simple Joke): {response}") - - chat_history = [ - {"role": "user", "content": "What is the capital of France?"}, - {"role": "assistant", "content": "The capital of France is Paris."} - ] - follow_up_prompt = "And what is a famous landmark there?" - response_with_history = call_llm(follow_up_prompt, history=chat_history) - print(f"LLM (Follow-up with History): {response_with_history}") \ No newline at end of file + # Test the LLM call + messages = [{"role": "user", "content": "In a few words, what's the meaning of life?"}] + response = call_llm(messages) + print(f"Prompt: {messages[0]['content']}") + print(f"Response: {response}") \ No newline at end of file