From 3c4ed48786cda3fafe2b5c4184684db08a68fa8d Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 29 Oct 2024 12:18:51 -0400 Subject: [PATCH] Refactor translate_to_french function to use the correct conversation setup --- examples/translate_text.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/translate_text.py b/examples/translate_text.py index e7d1d3e..b9e38d2 100644 --- a/examples/translate_text.py +++ b/examples/translate_text.py @@ -1,9 +1,13 @@ from _context import sm -conversation = sm.create_conversation(llm_model="gpt-4o", llm_provider="openai") -conversation.add_message( - "user", "Translate the following text to French: 'Hello, world!'" -) +def translate_to_french(text: str) -> str: + conversation = sm.create_conversation(llm_model="gpt-4o", llm_provider="openai") -print(conversation.send().text) + conversation.add_message( + "user", f"Translate the following text to French: {text!r}" + ) + return conversation.send().text + + +print(translate_to_french("Hello, world!"))