From 31dd206e848217b049778d9ada909b5f52a16f63 Mon Sep 17 00:00:00 2001 From: Guangya Liu Date: Fri, 17 May 2024 10:02:08 -0400 Subject: [PATCH] openai-langfuse --- langfuse/openai-test/openai-lf.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/langfuse/openai-test/openai-lf.py b/langfuse/openai-test/openai-lf.py index fe2e275..219fcbb 100644 --- a/langfuse/openai-test/openai-lf.py +++ b/langfuse/openai-test/openai-lf.py @@ -1,15 +1,22 @@ from dotenv import load_dotenv -import os load_dotenv() -from langfuse.openai import openai - -completion = openai.ChatCompletion.create( - name="test-chat-openai", - model="gpt-3.5-turbo", - messages=[ - {"role": "system", "content": "You are a very accurate calculator. You output only the result of the calculation."}, - {"role": "user", "content": "1 + 1 = "}], - temperature=0, - metadata={"someMetadataKey": "someValue"}, -) \ No newline at end of file +from langfuse.decorators import observe +from langfuse.openai import openai # OpenAI integration + +@observe() +def story(): + return openai.chat.completions.create( + model="gpt-3.5-turbo", + max_tokens=100, + messages=[ + {"role": "system", "content": "You are a great storyteller."}, + {"role": "user", "content": "Once upon a time in a galaxy far, far away..."} + ], + ).choices[0].message.content + +@observe() +def main(): + return story() + +main()