Javelin AI 閘道
Javelin AI 閘道 服務是適用於 AI 應用程式的高效能、企業級 API 閘道。
它旨在簡化組織內各種大型語言模型 (LLM) 供應商(例如 OpenAI、Cohere、Anthropic 和自訂大型語言模型)的使用和存取,方法是為與 LLM 的所有互動整合強大的存取安全性。
Javelin 提供高階介面,透過提供統一端點來處理特定的 LLM 相關請求,從而簡化與 LLM 的互動。
請參閱 Javelin AI 閘道文件以取得更多詳細資訊。
Javelin Python SDK 是一個易於使用的用戶端程式庫,旨在嵌入到 AI 應用程式中
安裝與設定
安裝 javelin_sdk
以與 Javelin AI 閘道互動
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="https://#: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="https://#: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="https://#:8000",
route="mychatbot_route",
model_name="gpt-3.5-turbo"
params={
"temperature": 0.1
}
)
print(chat(messages))