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 asynchronous generate interface #30001

Merged
merged 7 commits into from
Feb 28, 2025
Merged

Conversation

TheSongg
Copy link
Contributor

@TheSongg TheSongg commented Feb 26, 2025

  • PR title: [langchain_community.llms.xinference]: Add asynchronous generate interface

  • PR message: The asynchronous generate interface support stream data and non-stream data.

      chain = prompt | llm
      async for chunk in chain.astream(input=user_input):
          yield chunk
    
  • Add tests and docs:

     from langchain_community.llms import Xinference
     from langchain.prompts import PromptTemplate
    
     llm = Xinference(
     server_url="http://0.0.0.0:9997",  # replace your xinference server url
     model_uid={model_uid}  # replace model_uid with the model UID return from launching the model
         stream = True
          )
     prompt = PromptTemplate(input=['country'], template="Q: where can we visit in the capital of {country}? A:")
     chain = prompt | llm
     async for chunk in chain.astream(input=user_input):
         yield chunk
    

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Feb 26, 2025
Copy link

vercel bot commented Feb 26, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchain ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 27, 2025 2:46am

@dosubot dosubot bot added the community Related to langchain-community label Feb 26, 2025
Copy link
Collaborator

@ccurme ccurme left a comment

Choose a reason for hiding this comment

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

How is authentication handled here?

@ccurme
Copy link
Collaborator

ccurme commented Feb 26, 2025

Does their client not support async calls?

@ccurme ccurme self-assigned this Feb 26, 2025
@TheSongg
Copy link
Contributor Author

Does their client not support async calls?

no,xinference client only support sync call. In addition, langchain_community.chat_models doesn't support xinference chat client.
https://github.com/xorbitsai/inference/blob/main/xinference/client/restful/restful_client.py
image

@TheSongg
Copy link
Contributor Author

How is authentication handled here?

In fact, there was no authentication during initialization.
https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/llms/xinference.py
image

@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Feb 28, 2025
@ccurme ccurme merged commit 86b364d into langchain-ai:master Feb 28, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Related to langchain-community lgtm PR looks good. Use to confirm that a PR is ready for merging. size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants