Skip to main content

Javelin AI 网关

Javelin AI 网关 服务是一个高性能、企业级的 API 网关,专为 AI 应用而设计。 它旨在简化对各种大型语言模型 (LLM) 大模型供应商的使用和访问, 例如 OpenAI、Cohere、Anthropic 以及组织内的自定义大型语言模型,通过整合 对所有与 LLM 交互的强大访问安全性。

Javelin 提供了一个高级接口,通过提供统一的端点来简化与 LLM 的交互, 以处理特定的 LLM 相关请求。

有关更多详细信息,请参见 Javelin AI 网关 文档Javelin Python SDK 是一个易于使用的客户端库,旨在嵌入到 AI 应用中。

安装和设置

安装 javelin_sdk 以与 Javelin AI Gateway 交互:

pip install 'javelin_sdk'

将Javelin的API密钥设置为环境变量:

export JAVELIN_API_KEY=...

完成示例


from langchain.chains import LLMChain
from langchain_community.llms import JavelinAIGateway
from langchain_core.prompts import PromptTemplate

route_completions = "eng_dept03"

gateway = JavelinAIGateway(
gateway_uri="http://localhost:8000",
route=route_completions,
model_name="text-davinci-003",
)

llmchain = LLMChain(llm=gateway, prompt=prompt)
result = llmchain.run("podcast player")

print(result)

嵌入示例

from langchain_community.embeddings import JavelinAIGatewayEmbeddings
from langchain_openai import OpenAIEmbeddings

embeddings = JavelinAIGatewayEmbeddings(
gateway_uri="http://localhost:8000",
route="embeddings",
)

print(embeddings.embed_query("hello"))
print(embeddings.embed_documents(["hello"]))

聊天示例

from langchain_community.chat_models import ChatJavelinAIGateway
from langchain_core.messages import HumanMessage, SystemMessage

messages = [
SystemMessage(
content="You are a helpful assistant that translates English to French."
),
HumanMessage(
content="Artificial Intelligence has the power to transform humanity and make the world a better place"
),
]

chat = ChatJavelinAIGateway(
gateway_uri="http://localhost:8000",
route="mychatbot_route",
model_name="gpt-3.5-turbo"
params={
"temperature": 0.1
}
)

print(chat(messages))


Was this page helpful?


You can also leave detailed feedback on GitHub.

扫我,入群扫我,找书