-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
怎么用dspy里的方法来调用deepseek? #71
Comments
I made a custom model for DeepSeek: import requests
from dsp import LM
class DeepSeek(LM):
def __init__(self, model, api_key, **kwargs,):
self.model = model
self.api_key = api_key
self.provider = "default"
self.history = []
self.kwargs = {
"temperature": kwargs.get("temperature", 0.0),
"max_tokens": min(kwargs.get("max_tokens", 4096), 4096),
"top_p": kwargs.get("top_p", 0.95),
"top_k": kwargs.get("top_k", 1),
"n": kwargs.pop("n", kwargs.pop("num_generations", 1)),
**kwargs,
}
self.kwargs["model"] = model
self.base_url = "https://api.deepseek.com/chat/completions"
def basic_request(self, prompt: str, **kwargs):
headers = {
"Authorization": "Bearer " + self.api_key,
"Accept": "application/json",
"Content-Type": "application/json"
}
data = {
**kwargs,
"model": self.model,
"messages": [
{"role": "user", "content": prompt}
],
"steam": False
}
response = requests.post(self.base_url, headers=headers, json=data)
response = response.json()
self.history.append({
"prompt": prompt,
"response": response,
"kwargs": kwargs,
})
return response
def __call__(self, prompt, **kwargs):
response = self.request(prompt, **kwargs)
completions = [result['message']['content'] for result in response["choices"]]
return completions Then I could run it by importing the class: import dspy
import os
from DeepSeek import DeepSeek
lm = DeepSeek(model='deepseek-coder', api_key=os.getenv("DEEPSEEK_PALTFORM_API_KEY"))
dspy.configure(lm=lm)
qa = dspy.ChainOfThought('question -> answer')
response = qa(question="What is the capital of Paris?")
print(response.answer) |
Thank you ,it works well |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
我最近有一项dspy的prompt实验,想对比一下不同llm的效果,我不知道该如何接入deepseek,使用官方的OpenAI方法会报错:
上面gpt4方法可以正常调用,deepseek会报下面这个错误:
NotFoundError: Error code: 404 - {'error': {'message': 'Invalid URL (POST /v1chat/completions)', 'type': 'invalid_request_error', 'param': '', 'code': ''}}
具体错误为:
请问该怎么解决这个问题?
The text was updated successfully, but these errors were encountered: