lm=dspy.LM("openai/meta-llama/Meta-Llama-3-8B-Instruct",api_base="http://localhost:7501/v1",# ensure this points to your portapi_key="",model_type='chat')dspy.configure(lm=lm)
lm("Say this is a test!",temperature=0.7)# => ['This is a test!']lm(messages=[{"role":"user","content":"Say this is a test!"}])# => ['This is a test!']
# Define a module (ChainOfThought) and assign it a signature (return an answer, given a question).qa=dspy.ChainOfThought('question -> answer')# Run with the default LM configured with `dspy.configure` above.response=qa(question="How many floors are in the castle David Gregory inherited?")print(response.answer)
dspy.configure(lm=dspy.LM('openai/gpt-4o-mini'))response=qa(question="How many floors are in the castle David Gregory inherited?")print('GPT-4o-mini:',response.answer)withdspy.context(lm=dspy.LM('openai/gpt-3.5-turbo')):response=qa(question="How many floors are in the castle David Gregory inherited?")print('GPT-3.5-turbo:',response.answer)
可能的输出
GPT-4o: The number of floors in the castle David Gregory inherited cannot be determined with the information provided.
GPT-3.5-turbo: The castle David Gregory inherited has 7 floors.