Skip to main content
Javelin AI 网关服务是一款面向 AI 应用的高性能企业级 API 网关。 它旨在通过为所有 LLM 交互提供强健的访问安全机制,简化组织内部对各大语言模型(LLM)提供商(如 OpenAI、Cohere、Anthropic 及自定义大语言模型)的使用与访问。 Javelin 提供高层次接口,通过统一的端点处理特定的 LLM 相关请求,从而简化与 LLM 的交互。 更多详情请参阅 Javelin AI 网关文档Javelin Python SDK 是一个易用的客户端库,可嵌入 AI 应用中。

安装与设置

安装 javelin_sdk 以与 Javelin AI 网关交互:
pip install 'javelin_sdk'
将 Javelin 的 API key 设置为环境变量:
export JAVELIN_API_KEY=...

补全示例

from langchain_classic.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.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))