langflow-ai / langflow

Langflow is a low-code app builder for RAG and multi-agent AI applications. It’s Python-based and agnostic to any model, API, or database.
http://www.langflow.org
MIT License
34.17k stars 4.13k forks source link

How to use components to invoke Qwen models #3864

Closed alex-ge123 closed 2 weeks ago

alex-ge123 commented 1 month ago

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 commented 1 month ago

微信图片_20240920151229

dosubot[bot] commented 1 month ago

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.

carlosrcoelho commented 2 weeks ago

@alex-ge123

Sorry for the delayed response.

Do you still need support with this issue?

alex-ge123 commented 2 weeks ago

@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?

carlosrcoelho commented 2 weeks ago

@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.