Skip to content
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

Add support for deepseek #534

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

PengHongyiNTU
Copy link
Contributor


Add support for deepseek official api

Description

This PR adds support for the Deepseek API. Since Deepseek uses an OpenAI-compatible API, the wrapper is almost the same as the OpenAI one. The key difference lies in the yield generator, which now needs to access both the content and reasoning_content fields from the response.

issues

  1. The Deepseek official URL is often unresponsive. For testing and debugging, use the Aliyun-hosted version as a fallback.

  2. The streaming handling in logging.py causes bugs when displaying flags to indicate whether reasoning and final answer generation have started. Consider a better implementation.

  3. Streaming content can be a bit chunky because responses arrive faster than they are consumed. A better implementation (e.g., buffering or fixed-rate throttling) is needed to handle streaming more effectively.

Copy link
Collaborator

@DavdGao DavdGao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see inline comments and

  1. Add unittests for deepseek model wrapper.
  2. Update doc, including tutorial and README.md

)

# from agentscope.agents import DialogAgent
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary changes.

@@ -56,7 +56,14 @@ def log_stream_msg(msg: Msg, last: bool = True) -> None:

# Print msg to terminal
formatted_str = msg.formatted_str(colored=True)


# Debug prefix tracking
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove debug loggings

@@ -48,3 +48,61 @@ def _verify_text_content_in_openai_message_response(response: dict) -> bool:
return False

return True


def _verify_reasoning_content_in_openai_message_response(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

openai or deepseek or both?

def __init__(
self,
config_name: str,
model_name: Optional[str] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model_name is a required parameter

# then the model name is deepseek-r1 and deepseek-v3

# supported_models: list[str] = [
# "deepseek-chat",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't hope developers to modify this file, it's suggested to add deepseek-r1 and deepseek-v3 into the supported models.

generate_args: Optional[dict] = None,
**kwargs: Any,
) -> None:
"""Initalize the openai client.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the docstrings for deepseek.

if usage is not None:
self.monitor.update_text_and_embedding_tokens(
model_name=self.model_name,
prompt_tokens=usage.get("prompt_tokens", 0),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about reasoning tokens?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants