langflow icon indicating copy to clipboard operation
langflow copied to clipboard

How to use components to invoke Qwen models

Open alex-ge123 opened this issue 1 year ago • 2 comments

Bug Description

How to use components to invoke Qwen models 微信图片_20240920151229

Reproduction

image

Expected behavior

image

Who can help?

No response

Operating System

windows

Langflow Version

1.0.18

Python Version

3.11

Screenshot

No response

Flow File

No response

alex-ge123 avatar Sep 20 '24 07:09 alex-ge123

微信图片_20240920151229

alex-ge123 avatar Sep 20 '24 07:09 alex-ge123

To use components to invoke Qwen models, you can follow a structure similar to the one provided for the Baidu Qianfan model in the Langflow documentation. Here is an example based on the structure of the QianfanChatEndpointComponent:

from langchain_community.chat_models.baidu_qianfan_endpoint import QianfanChatEndpoint
from pydantic.v1 import SecretStr

# Define the parameters for the Qwen model
parameters = {
    "model": "Qwen/Qwen1.5-72B-Chat",  # Replace with the actual Qwen model name
    "qianfan_ak": "your-qwen-api-key",  # Replace with your Qwen API key
    "qianfan_sk": "your-qwen-secret-key",  # Replace with your Qwen secret key
    "top_p": 0.8,  # Set the top_p parameter
    "temperature": 0.1,  # Set the temperature for randomness
    "penalty_score": 1.0,  # Set the penalty score
    "endpoint": "your-qwen-endpoint"  # Replace with your Qwen endpoint
}

# Create an instance of the Qwen model
try:
    qwen_model = QianfanChatEndpoint(
        model=parameters["model"],
        qianfan_ak=SecretStr(parameters["qianfan_ak"]),
        qianfan_sk=SecretStr(parameters["qianfan_sk"]),
        top_p=parameters["top_p"],
        temperature=parameters["temperature"],
        penalty_score=parameters["penalty_score"],
        endpoint=parameters["endpoint"]
    )
except Exception as e:
    raise ValueError("Could not connect to Qwen API.") from e

# Generate text using the Qwen model
output = qwen_model.generate_text("Your input text here")  # Replace with your input text

# Print the generated text
print(output)

This example assumes that the Qwen model component follows a similar pattern to the Baidu Qianfan model. You would need to replace the placeholders with actual values and ensure that the QianfanChatEndpoint class and its methods are correctly implemented. For detailed documentation and integration guides, you can refer to the specific component documentation for other models like Amazon Bedrock, Anthropic, Azure OpenAI, etc., as they provide a comprehensive list of parameters and usage examples [1][2][3][4].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Sep 20 '24 07:09 dosubot[bot]

@alex-ge123

Sorry for the delayed response.

Do you still need support with this issue?

carlosrcoelho avatar Oct 29 '24 20:10 carlosrcoelho

@alex-ge123

Sorry for the delayed response.

Do you still need support with this issue?

Can you develop a component for an Alibaba Qianwen model or a model from Baidu, which is suitable for the Chinese market?

alex-ge123 avatar Oct 30 '24 01:10 alex-ge123

@alex-ge123 That's a great request! You can open a feature request issue, and then I will add it to our pipeline for new components for Langflow. Thank you very much for your suggestion.

carlosrcoelho avatar Oct 31 '24 14:10 carlosrcoelho

We hope to be able to directly integrate Alibaba Cloud’s Qwen (Tongyi Qianwen) model into LangFlow. Currently, the system only supports a few preset providers and lacks a custom or REST API interface. It would be helpful to add official support or provide an example so users can easily integrate the Qwen model.

jiangjianghong avatar Oct 23 '25 01:10 jiangjianghong