langflow-ai/langflow

How to use components to invoke Qwen models

alex-ge123 opened this issue · 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

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.