Skip to content

如何换别的模型,不会改代码orz #598

@hTp34r

Description

@hTp34r

llm.py中,源代码是这样的:

    from openai import OpenAI
    client = OpenAI(
        # 如果您没有配置环境变量,请在此处用您的API Key进行替换
        api_key=os.getenv("DASHSCOPE_API_KEY"),
        # 填写DashScope SDK的base_url
        base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
    )
    end = time.perf_counter()
    logger.info(f"llm Time init: {end-start}s,{message}")
    completion = client.chat.completions.create(
        model="qwen-plus",
        messages=[{'role': 'system', 'content': '你是一个知识助手,尽量以简短、口语化的方式输出'},
                {'role': 'user', 'content': message}],
        stream=True,
        # 通过以下设置,在流式输出的最后一行展示token使用信息
        stream_options={"include_usage": True}
    )

如果只是根据教程改动DASHSCOPE_API_KEY似乎不顶事,会弹出下列报错:

Traceback (most recent call last):
File "D:\LiveTalking\llm.py", line 13, in llm_response
client = OpenAI(
File "D:\miniconda3\envs\nerfstream\lib\site-packages\openai_client.py", line 158, in init
raise OpenAIError(
openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

问:如果有千问的API,改如何合理改动这部分使得可以接入过去呀QWQ(总不能只能去用OPENAI_API_KEY吧

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions