Documentation Index
Fetch the complete documentation index at: https://langchain-zh.cn/llms.txt
Use this file to discover all available pages before exploring further.
Banana 为 AI 模型提供无服务器 GPU 推理、
一个 CI/CD 构建管道以及一个简单的 Python 框架(Potassium),用于托管您的模型。
本页介绍如何在 LangChain 中使用 Banana 生态系统。
安装和设置
- 从 Banana.dev 仪表板 获取 Banana API 密钥,并将其设置为环境变量(
BANANA_API_KEY)
- 从模型的详细信息页面获取您的模型密钥和 URL 标识符。
定义您的 Banana 模板
您需要为您的 Banana 应用设置一个 GitHub 仓库。您可以使用 此指南 在 5 分钟内开始操作。
或者,如果您需要一个现成的 LLM 示例,可以查看 Banana 的 CodeLlama-7B-Instruct-GPTQ GitHub 仓库。只需将其 Fork 并在 Banana 内部署即可。
其他启动仓库可在 Banana.dev 启动仓库 中找到。
构建 Banana 应用
要在 LangChain 中使用 Banana 应用,您必须在返回的 JSON 中包含 outputs 键,并且该值必须是一个字符串。
# Return the results as a dictionary
result = {'outputs': result}
推理函数的示例如下:
@app.handler("/")
def handler(context: dict, request: Request) -> Response:
"""Handle a request to generate code from a prompt."""
model = context.get("model")
tokenizer = context.get("tokenizer")
max_new_tokens = request.json.get("max_new_tokens", 512)
temperature = request.json.get("temperature", 0.7)
prompt = request.json.get("prompt")
prompt_template=f'''[INST] Write code to solve the following coding problem that obeys the constraints and passes the example test cases. Please wrap your code answer using ```:
{prompt}
[/INST]
'''
input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids.cuda()
output = model.generate(inputs=input_ids, temperature=temperature, max_new_tokens=max_new_tokens)
result = tokenizer.decode(output[0])
return Response(json={"outputs": result}, status=200)
此示例来自 CodeLlama-7B-Instruct-GPTQ 中的 app.py 文件。
LLM
from langchain_community.llms import Banana
查看 使用示例。