18 lines
731 B
Python
18 lines
731 B
Python
import dspy
|
|
lm = dspy.LM("openai/deepseek-chat", api_key="sk-6129a200ae294b9f86553505191fa477", api_base="https://api.deepseek.com")
|
|
dspy.configure(lm=lm)
|
|
|
|
# print(lm("Say this is a test!", temperature=0.7)) # => ['This is a test!']
|
|
# print(lm(messages=[{"role": "user", "content": "Say this is a test!"}])) # => ['This is a test!']
|
|
|
|
from typing import Literal
|
|
|
|
class Classify(dspy.Signature):
|
|
"""Classify sentiment of a given sentence."""
|
|
|
|
sentence: str = dspy.InputField()
|
|
sentiment: Literal["positive", "negative", "neutral"] = dspy.OutputField()
|
|
confidence: float = dspy.OutputField()
|
|
|
|
classify = dspy.Predict(Classify)
|
|
print(classify(sentence="This book was super fun to read, though not the last chapter.")) |