Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
OurBuilding Ambient Agents with LangGraph course is now available on LangChain Academy!
Open In ColabOpen on GitHub

Gradient

Gradient allows to createEmbeddings as well fine tune and get completions on LLMs with a simple web API.

This notebook goes over how to use Langchain with Embeddings ofGradient.

Imports

from langchain_community.embeddingsimport GradientEmbeddings
API Reference:GradientEmbeddings

Set the Environment API Key

Make sure to get your API key from Gradient AI. You are given $10 in free credits to test and fine-tune different models.

import os
from getpassimport getpass

ifnot os.environ.get("GRADIENT_ACCESS_TOKEN",None):
# Access token under https://auth.gradient.ai/select-workspace
os.environ["GRADIENT_ACCESS_TOKEN"]= getpass("gradient.ai access token:")
ifnot os.environ.get("GRADIENT_WORKSPACE_ID",None):
# `ID` listed in `$ gradient workspace list`
# also displayed after login at at https://auth.gradient.ai/select-workspace
os.environ["GRADIENT_WORKSPACE_ID"]= getpass("gradient.ai workspace id:")

Optional: Validate your environment variablesGRADIENT_ACCESS_TOKEN andGRADIENT_WORKSPACE_ID to get currently deployed models. Using thegradientai Python package.

%pip install--upgrade--quiet  gradientai

Create the Gradient instance

documents=[
"Pizza is a dish.",
"Paris is the capital of France",
"numpy is a lib for linear algebra",
]
query="Where is Paris?"
embeddings= GradientEmbeddings(model="bge-large")

documents_embedded= embeddings.embed_documents(documents)
query_result= embeddings.embed_query(query)
# (demo) compute similarity
import numpyas np

scores= np.array(documents_embedded) @ np.array(query_result).T
dict(zip(documents, scores))

Related


[8]ページ先頭

©2009-2025 Movatter.jp