
generative-ai-for-beginners 第6课基于 OpenAI 客户端与 Responses API 构建文本生成应用【免费下载链接】generative-ai-for-beginners21 Lessons, Get Started Building with Generative AI项目地址: https://gitcode.com/GitHub_Trending/ge/generative-ai-for-beginners本篇指南基于课程仓库的 06 课文档系统讲解如何用openaiPython 库与 Responses API 从零搭建一个文本生成应用从环境配置、密钥管理到 Prompt 设计、max_output_tokens与temperature调参并通过仓库中配套的食谱生成器recipe generator完整实战代码掌握“提示词迭代 多步提示 上下文传递”的核心技术。读完并动手完成后你将具备独立构建食谱生成器、学习伙伴study buddy、历史角色问答机器人history bot等文本生成应用的能力。1. 什么是文本生成应用传统应用通常具备某种固定界面命令式应用Command-based控制台输入命令、执行任务例如git图形界面应用UI点击按钮、输入文本、选择选项的 GUI。这类应用存在两个固有局限能力受限只能执行应用预先支持的命令无法任意输入语言绑定应用默认面向特定语言构建扩展其他语言支持需要额外开发。文本生成应用则不同你不再受限于固定的命令集或输入语言而是用自然语言与应用交互。另一个关键收益是你直接对接的是一个在海量语料上训练过的数据源而传统应用往往只能查询数据库里已有的有限内容。典型的文本生成应用形态包括聊天机器人回答关于某主题例如你的公司与产品的问题助手类应用LLM 擅长文本摘要、从文本中提炼洞见、生成简历等文本产出代码助手视所选语言模型而定可辅助编写代码。2. 与 LLM 集成的两条路线API 与 SDK要把这种体验加入自己的应用你需要理解 prompt、completion 等概念并选择一个库来工作。集成的方式通常有两类直接调用 API用 prompt 构造 Web 请求取回生成的文本使用库/SDK库对 API 调用做了封装用起来更简单。课程推荐的常用库包括openai让连接模型并发送 prompt 变得简单本课主线更高层的框架Langchain知名、支持 Python、Semantic Kernel微软出品支持 C#、Python、Java。本仓库 06 课同时提供了 Python 与 TypeScript 两套实现Python 侧使用openai官方库见 python 目录TypeScript 侧使用 Azure AI Inference 的 REST 客户端见 js-githubmodels/app.js。3. 环境准备安装 openai 库与创建资源3.1 安装 openai交互 OpenAI / Azure OpenAI 的库很多也支持 C#、Python、JavaScript、Java 等多种语言。课程选择openaiPython 库用pip安装pip install openai仓库中 06 课的依赖清单 锁定了具体版本可直接复现openai1.55.1 python-dotenv1.2.23.2 创建 Azure OpenAI 资源若走 Azure OpenAI现已并入 Microsoft Foundry路线需要依次完成注册 Azure 免费账户azure.microsoft.com/free申请 Azure OpenAI 的访问资格提交 access 申请安装 Python在 Azure 门户创建 Azure OpenAI 服务资源并部署模型部署名即后续代码中的deployment。3.3 定位 API Key 与 Endpoint在 Azure OpenAI 资源的“Keys and Endpoint”页签中复制Key 1的值与资源端点。值得把 API key 与代码分离标准做法是使用环境变量例如在终端执行export OPENAI_API_KEYsk-...Azure 路线则设置AZURE_OPENAI_API_KEY与AZURE_OPENAI_ENDPOINT。os.environ负责读取环境变量也可用dotenv这类库从文件加载。仓库配套代码正是这么做的aoai-app.py 开头先load_dotenv()再构造客户端此外仓库还提供了通用的 shared/python/env_utils.py 工具模块其中的get_required_env()会在环境变量缺失时抛出带提示信息“请在 .env 文件中设置”的ValueError避免带着空配置悄悄运行。4. 配置客户端标准 OpenAI 客户端指向 Azure OpenAI如果走 Azure OpenAIMicrosoft Foundry路线仓库的做法是用标准OpenAI客户端指向 Azure OpenAI 的/openai/v1/端点该稳定 v1 端点同时兼容 OpenAI 与 Azure OpenAI且无需管理api_versionimport os from openai import OpenAI client OpenAI( api_keyos.environ[AZURE_OPENAI_API_KEY], base_urlf{os.environ[AZURE_OPENAI_ENDPOINT].rstrip(/)}/openai/v1/, )api_keyAzure Portal / Microsoft Foundry 门户中的 API keybase_urlFoundry 资源端点加上/openai/v1/后缀。对照仓库源码可以印证细节aoai-app.py 与 aoai-app-recipe.py 都是同样的OpenAI(api_key..., base_url...)写法并通过rstrip(/)防止端点末尾斜杠造成双斜杠而 oai-app.py 走纯 OpenAI 路线直接client OpenAI()API key 自动从OPENAI_API_KEY读取不传base_url模型名固定为gpt-4o-mini。5. 生成文本Responses API 与多轮对话生成文本的核心是Responses API的responses.create方法prompt Complete the following: Once upon a time there was a response client.responses.create( modelgpt-4o-mini, # 模型或部署名 inputprompt, storeFalse, ) print(response.output_text)要点说明modelAzure 路线填部署名deployment纯 OpenAI 路线填模型名如gpt-4o-miniinput本次请求的提示词字符串或消息列表storeFalse不落盘存储本次响应适合无状态调用response.output_text直接取出模型生成的文本。关于多轮对话Responses API 同样适用于单轮文本生成与多轮聊天机器人通过input传入消息列表即可累积会话上下文。真正的多轮聊天实现在课程第 7 课07 课文档展开本篇聚焦单轮生成。6. 练习一你的第一个文本生成应用6.1 创建虚拟环境并安装依赖python -m venv venv source venv/bin/activate pip install openaiWindows 下请用venv\Scripts\activate代替source venv/bin/activate。同时到 Azure 门户搜索Open AI选中你的资源进入Keys and Endpoint复制Key 1。6.2 编写 app.pyimport os from openai import OpenAI client OpenAI( api_key替换为你的 Azure OpenAI key, base_urlAzure 门户中的端点/openai/v1/, ) deployment_name 部署名 # 添加你的补全代码 prompt Complete the following: Once upon a time there was a # 使用 Responses API 发起请求 response client.responses.create(modeldeployment_name, inputprompt, storeFalse) # 打印响应 print(response.output_text)如果使用纯 OpenAI而非 Azureclient OpenAI(api_key你的 OpenAI key)不传base_url并把部署名换成模型名如gpt-4o-mini。运行后你会看到类似如下输出very unhappy _____. Once upon a time there was a very unhappy mermaid.这个最小可用版本与仓库中的 aoai-app.py / oai-app.py 完全对应注释中还保留了示例输出的原文方便比对。7. 不同类型的提示词对应不同的事生成文本跑通之后你可以修改 prompt 生成不同类型的文本。提示词可用于各种任务生成某种类型的文本生成一首诗、生成测验题目等查询信息例如 “What does CORS mean in web development?”生成代码例如生成校验邮箱的正则表达式甚至生成整个 Web 应用程序。8. 实战用例食谱生成器Recipe Generator场景家里有一些食材想做一道菜。除了搜索引擎也可以用 LLM 来“找”食谱。第一步提示词“Show me 5 recipes for a dish with the following ingredients: chicken, potatoes, and carrots. Per recipe, list all the ingredients used”模型会返回类似如下结果节选原文档示例1. Roasted Chicken and Vegetables: Ingredients: - 4 chicken thighs - 2 potatoes, cut into cubes - 2 carrots, cut into cubes - 2 tablespoons olive oil - 2 cloves garlic, minced - 1 teaspoon dried thyme - 1 teaspoon dried oregano - Salt and pepper, to taste 2. Chicken and Potato Stew: Ingredients: - 2 tablespoons olive oil - 1 onion, diced - 2 cloves garlic, minced - 2 chicken breasts, cut into cubes - 2 potatoes, cut into cubes - 2 carrots, cut into cubes - 1 teaspoon dried oregano - 1 teaspoon dried thyme - 1 cup chicken broth - Salt and pepper, to taste 3. Chicken and Potato Bake: Ingredients: - 2 tablespoons olive oil - 2 chicken breasts, cut into cubes - 2 potatoes, cut into cubes - 2 carrots, cut into cubes - 1 onion, diced - 2 cloves garlic, minced - 1 teaspoon dried oregano - 1 teaspoon dried thyme - 1 cup chicken broth - Salt and pepper, to taste 4. Chicken and Potato Soup: Ingredients: - 2 tablespoons olive oil - 1 onion, diced - 2 cloves garlic, minced - 2 chicken breasts, cut into cubes - 2 potatoes, cut into cubes - 2 carrots, cut into cubes - 1 teaspoon dried oregano - 1 teaspoon dried thyme - 4 cups chicken broth - Salt and pepper, to taste 5. Chicken and Potato Hash: Ingredients: - 2 tablespoons olive oil - 2 chicken breasts, cut into cubes - 2 potatoes, cut into cubes - 2 carrots, cut into cubes - 1 onion, diced - 2 cloves garlic, minced - 1 teaspoon dried oregano这个结果已经可用但还有两个有价值的改进方向过滤掉不喜欢的/过敏的食材生成购物清单考虑家里已有的食材。于是追加一条提示“Please remove recipes with garlic as Im allergic and replace it with something else. Also, please produce a shopping list for the recipes, considering I already have chicken, potatoes and carrots at home.”再次得到的结果中所有含大蒜的食谱已被剔除并且末尾多了一份购物清单1. Roasted Chicken and Vegetables: Ingredients: - 4 chicken thighs - 2 potatoes, cut into cubes - 2 carrots, cut into cubes - 2 tablespoons olive oil - 1 teaspoon dried thyme - 1 teaspoon dried oregano - Salt and pepper, to taste 2. Chicken and Potato Stew: Ingredients: - 2 tablespoons olive oil - 1 onion, diced - 2 chicken breasts, cut into cubes - 2 potatoes, cut into cubes - 2 carrots, cut into cubes - 1 teaspoon dried oregano - 1 teaspoon dried thyme - 1 cup chicken broth - Salt and pepper, to taste 3. Chicken and Potato Bake: Ingredients: - 2 tablespoons olive oil - 2 chicken breasts, cut into cubes - 2 potatoes, cut into cubes - 2 carrots, cut into cubes - 1 onion, diced - 1 teaspoon dried oregano - 1 teaspoon dried thyme - 1 cup chicken broth - Salt and pepper, to taste 4. Chicken and Potato Soup: Ingredients: - 2 tablespoons olive oil - 1 onion, diced - 2 chicken breasts, cut into cubes - 2 potatoes, cut into cubes - 2 carrots, cut into cubes - 1 teaspoon dried oregano - 1 teaspoon dried thyme - 4 cups chicken broth - Salt and pepper, to taste 5. Chicken and Potato Hash: Ingredients: - 2 tablespoons olive oil - 2 chicken breasts, cut into cubes - 2 potatoes, cut into cubes - 2 carrots, cut into cubes - 1 onion, diced - 2 cloves garlic, minced - 1 teaspoon dried oregano Shopping List: - Olive oil - Onion - Thyme - Oregano - Salt - Pepper五份食谱中不再出现大蒜同时得到了考虑现有库存的购物清单。接下来把这个演示过程写成真正的代码。9. 练习二逐步构建食谱生成器9.1 硬编码提示词的第一版以现有app.py为起点把prompt变量改为prompt Show me 5 recipes for a dish with the following ingredients: chicken, potatoes, and carrots. Per recipe, list all the ingredients used运行后你会看到类似输出原文档示例注意 LLM 具有非确定性每次运行结果可能不同-Chicken Stew with Potatoes and Carrots: 3 tablespoons oil, 1 onion, chopped, 2 cloves garlic, minced, 1 carrot, peeled and chopped, 1 potato, peeled and chopped, 1 bay leaf, 1 thyme sprig, 1/2 teaspoon salt, 1/4 teaspoon black pepper, 1 1/2 cups chicken broth, 1/2 cup dry white wine, 2 tablespoons chopped fresh parsley, 2 tablespoons unsalted butter, 1 1/2 pounds boneless, skinless chicken thighs, cut into 1-inch pieces -Oven-Roasted Chicken with Potatoes and Carrots: 3 tablespoons extra-virgin olive oil, 1 tablespoon Dijon mustard, 1 tablespoon chopped fresh rosemary, 1 tablespoon chopped fresh thyme, 4 cloves garlic, minced, 1 1/2 pounds small red potatoes, quartered, 1 1/2 pounds carrots, quartered lengthwise, 1/2 teaspoon salt, 1/4 teaspoon black pepper, 1 (4-pound) whole chicken -Chicken, Potato, and Carrot Casserole: cooking spray, 1 large onion, chopped, 2 cloves garlic, minced, 1 carrot, peeled and shredded, 1 potato, peeled and shredded, 1/2 teaspoon dried thyme leaves, 1/4 teaspoon salt, 1/4 teaspoon black pepper, 2 cups fat-free, low-sodium chicken broth, 1 cup frozen peas, 1/4 cup all-purpose flour, 1 cup 2% reduced-fat milk, 1/4 cup grated Parmesan cheese -One Pot Chicken and Potato Dinner: 2 tablespoons olive oil, 1 pound boneless, skinless chicken thighs, cut into 1-inch pieces, 1 large onion, chopped, 3 cloves garlic, minced, 1 carrot, peeled and chopped, 1 potato, peeled and chopped, 1 bay leaf, 1 thyme sprig, 1/2 teaspoon salt, 1/4 teaspoon black pepper, 2 cups chicken broth, 1/2 cup dry white wine -Chicken, Potato, and Carrot Curry: 1 tablespoon vegetable oil, 1 large onion, chopped, 2 cloves garlic, minced, 1 carrot, peeled and chopped, 1 potato, peeled and chopped, 1 teaspoon ground coriander, 1 teaspoon ground cumin, 1/2 teaspoon ground turmeric, 1/2 teaspoon ground ginger, 1/4 teaspoon cayenne pepper, 2 cups chicken broth, 1/2 cup dry white wine, 1 (15-ounce) can chickpeas, drained and rinsed, 1/2 cup raisins, 1/2 cup chopped fresh cilantro9.2 让应用灵活接收用户输入为了让“几份食谱”“哪些食材”都可以动态指定把硬编码改为input()收集 f-string 插值no_recipes input(No of recipes (for example, 5): ) ingredients input(List of ingredients (for example, chicken, potatoes, and carrots): ) # 将食谱数量与食材插值进提示词 prompt fShow me {no_recipes} recipes for a dish with the following ingredients: {ingredients}. Per recipe, list all the ingredients used一次实际运行可能长这样No of recipes (for example, 5): 3 List of ingredients (for example, chicken, potatoes, and carrots): milk,strawberries -Strawberry milk shake: milk, strawberries, sugar, vanilla extract, ice cubes -Strawberry shortcake: milk, flour, baking powder, sugar, salt, unsalted butter, strawberries, whipped cream -Strawberry milk: milk, strawberries, sugar, vanilla extract9.3 改进一过滤条件Filter加入过滤编辑现有 prompt在末尾追加过滤条件并从用户处捕获过滤值filter input(Filter (for example, vegetarian, vegan, or gluten-free): ) prompt fShow me {no_recipes} recipes for a dish with the following ingredients: {ingredients}. Per recipe, list all the ingredients used, no {filter}示例运行No of recipes (for example, 5): 3 List of ingredients (for example, chicken, potatoes, and carrots): onion,milk Filter (for example, vegetarian, vegan, or gluten-free): no milk 1. French Onion Soup Ingredients: -1 large onion, sliced -3 cups beef broth -1 cup milk -6 slices french bread -1/4 cup shredded Parmesan cheese -1 tablespoon butter -1 teaspoon dried thyme -1/4 teaspoon salt -1/4 teaspoon black pepper Instructions: 1. In a large pot, sauté onions in butter until golden brown. 2. Add beef broth, milk, thyme, salt, and pepper. Bring to a boil. 3. Reduce heat and simmer for 10 minutes. 4. Place french bread slices on soup bowls. 5. Ladle soup over bread. 6. Sprinkle with Parmesan cheese. 2. Onion and Potato Soup Ingredients: -1 large onion, chopped -2 cups potatoes, diced -3 cups vegetable broth -1 cup milk -1/4 teaspoon black pepper Instructions: 1. In a large pot, sauté onions in butter until golden brown. 2. Add potatoes, vegetable broth, milk, and pepper. Bring to a boil. 3. Reduce heat and simmer for 10 minutes. 4. Serve hot. 3. Creamy Onion Soup Ingredients: -1 large onion, chopped -3 cups vegetable broth -1 cup milk -1/4 teaspoon black pepper -1/4 cup all-purpose flour -1/2 cup shredded Parmesan cheese Instructions: 1. In a large pot, sauté onions in butter until golden brown. 2. Add vegetable broth, milk, and pepper. Bring to a boil. 3. Reduce heat and simmer for 10 minutes. 4. In a small bowl, whisk together flour and Parmesan cheese until smooth. 5. Add to soup and simmer for an additional 5 minutes, or until soup has thickened.可以看到含牛奶的食谱被过滤掉了。但如果你乳糖不耐受可能还想过滤含奶酪的食谱——提示词必须表述清楚模型才会按你的意图执行。9.4 改进二生成购物清单两阶段提示要生成购物清单可以“一个提示词全解决”也可以拆成两个提示词。课程选择后者把第一个提示词的结果作为第二个提示词的上下文。找到打印第一次结果的代码在其后添加old_prompt_result response.output_text prompt Produce a shopping list for the generated recipes and please dont include ingredients that I already have. new_prompt f{old_prompt_result} {prompt} response client.responses.create(modeldeployment_name, inputnew_prompt, max_output_tokens1200, storeFalse) # 打印响应 print(Shopping list:) print(response.output_text)两个关键细节构造新提示词 第一次结果 新指令new_prompt f{old_prompt_result} {prompt}。这就是文本生成应用里常见的“结果接力”模式——前一步的输出成为后一步的上下文控制输出长度既然要承接上一段食谱文本输出预算要放宽因此第二次请求显式指定max_output_tokens1200。实际运行效果原文档示例No of recipes (for example, 5): 2 List of ingredients (for example, chicken, potatoes, and carrots): apple,flour Filter (for example, vegetarian, vegan, or gluten-free): sugar -Apple and flour pancakes: 1 cup flour, 1/2 tsp baking powder, 1/2 tsp baking soda, 1/4 tsp salt, 1 tbsp sugar, 1 egg, 1 cup buttermilk or sour milk, 1/4 cup melted butter, 1 Granny Smith apple, peeled and grated -Apple fritters: 1-1/2 cups flour, 1 tsp baking powder, 1/4 tsp salt, 1/4 tsp baking soda, 1/4 tsp nutmeg, 1/4 tsp cinnamon, 1/4 tsp allspice, 1/4 cup sugar, 1/4 cup vegetable shortening, 1/4 cup milk, 1 egg, 2 cups shredded, peeled apples Shopping list: -Flour, baking powder, baking soda, salt, sugar, egg, buttermilk, butter, apple, nutmeg, cinnamon, allspice9.5 仓库中的完整参考实现两阶段请求 输入校验上面的练习代码在仓库中有更完整的工程化版本 aoai-app-recipe.py纯 OpenAI 版为 oai-app-recipe.py值得逐点对照学习环境变量强校验get_required_env(AZURE_OPENAI_API_KEY)等函数在关键变量缺失时直接抛错退出而不是带着空配置运行用户输入校验防止提示注入与越界参数def validate_number_input(value: str, min_val: int 1, max_val: int 20) - int: Validate and sanitize numeric input. try: num int(value) if num min_val or num max_val: raise ValueError(fNumber must be between {min_val} and {max_val}) return num except ValueError: raise ValueError(fPlease enter a valid number between {min_val} and {max_val}) def validate_text_input(value: str, max_length: int 500) - str: Validate and sanitize text input to prevent prompt injection. if len(value) max_length: raise ValueError(fInput too long. Maximum {max_length} characters allowed.) sanitized re.sub(r[{}[\]|\\], , value) if not re.match(r^[\w\s,.\-]$, sanitized, re.UNICODE): raise ValueError(Input contains invalid characters) return sanitized.strip()食谱数量被限制在120之间食材文本限制500 字符、过滤词限制100 字符并剔除{}等潜在注入字符 3.两阶段请求的温度策略第一次生成食谱用temperature0.1低随机性、结果更稳定第二次生成购物清单用temperature0几乎完全确定且两者都设置max_output_tokens600response client.responses.create(modeldeployment, inputprompt, max_output_tokens600, temperature0.1, storeFalse) # ... 打印食谱后 ... prompt_shopping Produce a shopping list, and please dont include ingredients that I already have at home: new_prompt fGiven ingredients at home {ingredients} and these generated recipes: {old_prompt_result}, {prompt_shopping} response client.responses.create(modeldeployment, inputnew_prompt, max_output_tokens600, temperature0, storeFalse)注意参考实现里第二个提示词的写法比练习版更严谨它不仅把食谱结果带入上下文还显式回传了“家里已有的食材”{ingredients}让“不要包含已有食材”这条指令有明确依据。此外代码对response.output_text为空的情况做了if not old_prompt_result的防御分支。TypeScript 路线的 js-githubmodels/app.js 实现了同样的两阶段流程但调用的是azure-rest/ai-inference的client.path(/chat/completions).post(...)temperature: 1.0、max_tokens: 1000、top_p: 1.0可以看到“食谱 → 购物清单”的上下文接力逻辑在不同 SDK 下是同构的。10. 改进你的设置密钥、Token 与温度目前代码可以跑但还有三类工程化改进。10.1 把密钥与代码分离密钥不属于代码应存放在安全位置。用环境变量 python-dotenv从文件加载创建.env文件OPENAI_API_KEYsk-...若使用 Azure OpenAIMicrosoft Foundry则改为AZURE_OPENAI_API_KEY替换 AZURE_OPENAI_ENDPOINT替换 AZURE_OPENAI_API_VERSION2024-10-21代码中加载环境变量import os from dotenv import load_dotenv from openai import OpenAI load_dotenv() client OpenAI(api_keyos.environ[OPENAI_API_KEY])仓库的所有 Python 示例都遵循这一模式from dotenv import load_dotenvload_dotenv()作为固定前置步骤见 oai-app.py、aoai-app-recipe.py。10.2 关于 Token 长度要生成想要的文本需要考虑需要多少 token——token 是计费单位应尽量经济地使用例如能否把提示词写得更短。用max_output_tokens参数控制输出上限例如限制为 100 个 tokenresponse client.responses.create(modeldeployment, inputprompt, max_output_tokens100, storeFalse)10.3 实验温度Temperature温度决定输出的随机程度值越高输出越随机值越低输出越可预测——需要变化多样的输出就调高需要稳定一致的输出就调低。用temperature参数调整例如设为 0.5response client.responses.create(modeldeployment, inputprompt, temperature0.5, storeFalse)越接近 1.0输出越多样。结合 9.5 节参考实现的用法可以总结一条实用经验生成创意内容食谱用 0.1 这样的低值生成清单类结构化输出用 0让每一步都在“稳定”和“多样”之间取得明确取舍。11. 作业与参考解法作业允许自选方向课程给出的三个建议及仓库中的参考实现打磨食谱生成器调整 temperature、修改提示词观察不同组合的效果构建“学习伙伴”study buddy回答某个主题例如 Python的问题提示词如 “What is a certain topic in Python?”。仓库中的 aoai-study-buddy.py 展示了如何把“专家人设 固定输出格式概念 / 示例代码 / 解释”写成结构化多行 prompt并用input()接收用户问题后插值进提示词历史机器人history bot让机器人扮演某个历史人物回答关于其生平与时代的问题。aoai-history-bot.py 的提示词中有一条很好的防幻觉约束“remember facts about the timelines and incidents and respond the accurate answer only. Dont create content yourself. If you dont know something, tell that you dont remember.”——即不知道就明说不要编造。课程文档给出的起始提示词- Youre an expert on the Python language Suggest a beginner lesson for Python in the following format: Format: - concepts: - brief explanation of the lesson: - exercise in code with solutions历史机器人示例提示词- You are Abe Lincoln, tell me about yourself in 3 sentences, and respond using grammar and words like Abe would have used - You are Abe Lincoln, respond using grammar and words like Abe would have used: Tell me about your greatest accomplishments, in 300 words12. 知识检查与进阶挑战知识检查temperature温度这个概念的作用是什么它控制输出的随机程度它控制响应的大小它控制使用的 token 数量。正确答案1。进阶挑战在做作业时有意识地变换温度——分别尝试 0、0.5 和 10 最稳定、1 最多样观察哪种取值最适合你的应用。本篇小结本课以openai库与 Responses API 为主线完整走通了“环境配置 → 最小生成应用 → 提示词迭代 → 两阶段提示接力 → 密钥/Token/温度工程化”的全流程。仓库中 06 课目录 下提供了aoai-app.py、oai-app.py、aoai-app-recipe.py、oai-app-recipe.py、aoai-study-buddy.py、aoai-history-bot.py六套可运行脚本及锁版依赖清单均可对照本文逐行复现。下一步可进入 07 课构建聊天应用把单轮文本生成升级为带上下文的多轮对话。【免费下载链接】generative-ai-for-beginners21 Lessons, Get Started Building with Generative AI项目地址: https://gitcode.com/GitHub_Trending/ge/generative-ai-for-beginners创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考