Skip to content

Commit

Permalink
openai-langfuse (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
gyliu513 committed May 17, 2024
1 parent 751e75d commit 7ba0915
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions langfuse/openai-test/openai-lf.py
Original file line number Diff line number Diff line change
@@ -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"},
)
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()

0 comments on commit 7ba0915

Please sign in to comment.