이것은 Vercel AI Playground의 리버스 엔지니어링 API 래퍼이며 OpenAi의 ChatGpt, Cohere의 Command Mightly 및 일부 오픈 소스 모델을 포함하여 많은 LLM에 무료로 액세스 할 수 있습니다.
Markdown-Toc으로 생성 된 목차.
다음 명령을 실행 하여이 라이브러리를 설치할 수 있습니다.
pip3 install vercel-llm-api
예제는 /examples 디렉토리에서 찾을 수 있습니다. 이 예제를 실행하려면 단자에서 포함 된 Python 파일을 실행하십시오.
python3 examples/generate.py
이 라이브러리를 사용하려면 vercel_ai 가져 와서 vercel_ai.Client 인스턴스를 작성하십시오. proxy 키워드 인수를 사용하여 프록시를 지정할 수 있습니다.
Normal example:
import vercel_ai
client = vercel_ai . Client ()프록시 된 예 :
import vercel_ai
client = vercel_ai . Client ( proxy = "socks5h://193.29.62.48:11003" ) 다음 예제는 client vercel_ai.Client 인스턴스의 이름이라고 가정합니다.
클라이언트는 초기화시 사용 가능한 모델을 다운로드하여 client.models 에 저장합니다.
>> > print ( json . dumps ( client . models , indent = 2 ))
{
"anthropic:claude-instant-v1" : {
"id" : "anthropic:claude-instant-v1" , #the model's id
"provider" : "anthropic" , #the model's provider
"providerHumanName" : "Anthropic" , #the provider's display name
"makerHumanName" : "Anthropic" , #the maker of the model
"minBillingTier" : "hobby" , #the minimum billing tier needed to use the model
"parameters" : { #a dict of optional parameters that can be passed to the generate function
"temperature" : { #the name of the parameter
"value" : 1 , #the default value for the parameter
"range" : [ 0 , 1 ] #a range of possible values for the parameter
},
...
}
...
}
} 아직 인증이 없으므로 모델에 "minBillingTier" 속성이있는 경우 사용할 수 없습니다.
모델 ID 목록은 client.model_ids 에서도 사용할 수 있습니다.
>> > print ( json . dumps ( client . model_ids , indent = 2 ))
[
"anthropic:claude-instant-v1" , #locked to hobby tier; unusable
"anthropic:claude-v1" , #locked to hobby tier; unusable
"replicate:replicate/alpaca-7b" ,
"replicate:stability-ai/stablelm-tuned-alpha-7b" ,
"huggingface:bigscience/bloom" ,
"huggingface:bigscience/bloomz" ,
"huggingface:google/flan-t5-xxl" ,
"huggingface:google/flan-ul2" ,
"huggingface:EleutherAI/gpt-neox-20b" ,
"huggingface:OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5" ,
"huggingface:bigcode/santacoder" ,
"cohere:command-medium-nightly" ,
"cohere:command-xlarge-nightly" ,
"openai:gpt-4" , #locked to pro tier; unusable
"openai:code-cushman-001" ,
"openai:code-davinci-002" ,
"openai:gpt-3.5-turbo" ,
"openai:text-ada-001" ,
"openai:text-babbage-001" ,
"openai:text-curie-001" ,
"openai:text-davinci-002" ,
"openai:text-davinci-003"
] 각 모델에 대한 기본 매개 변수의 덕트는 client.model_params 에서 찾을 수 있습니다.
>> > print ( json . dumps ( client . model_defaults , indent = 2 ))
{
"anthropic:claude-instant-v1" : {
"temperature" : 1 ,
"maximumLength" : 200 ,
"topP" : 1 ,
"topK" : 1 ,
"presencePenalty" : 1 ,
"frequencyPenalty" : 1 ,
"stopSequences" : [
" n n Human:"
]
},
...
} 일부 텍스트를 생성하려면 다음 인수를 수락하는 client.generate 함수를 사용하십시오.
model - 사용하려는 모델의 ID.prompt - 프롬프트.params = {} - 선택적 매개 변수의 덕트. 이것들을 찾는 방법은 이전 섹션을 참조하십시오.함수는 새로 생성 된 텍스트를 문자열로 리턴하는 생성기입니다.
스트림 예제 :
for chunk in client . generate ( "openai:gpt-3.5-turbo" , "Summarize the GNU GPL v3" ):
print ( chunk , end = "" , flush = True )스트리밍되지 않은 예 :
result = ""
for chunk in client . generate ( "openai:gpt-3.5-turbo" , "Summarize the GNU GPL v3" ):
result += chunk
print ( result ) 채팅 메시지를 생성하려면 client.chat 함수를 사용하여 다음 인수를 허용합니다.
model - 사용하려는 모델의 ID.messages - 메시지 목록. 이에 대한 형식은 공식 OpenAI API를 사용하는 방법과 동일합니다.params = {} - 선택적 매개 변수의 덕트. 찾는 방법은 "사용 가능한 모델 다운로드"섹션을 참조하십시오.함수는 새로 생성 된 텍스트를 문자열로 리턴하는 생성기입니다.
messages = [
{ "role" : "system" , "content" : "You are a helpful assistant." },
{ "role" : "user" , "content" : "Who won the world series in 2020?" },
{ "role" : "assistant" , "content" : "The Los Angeles Dodgers won the World Series in 2020." },
{ "role" : "user" , "content" : "Where was it played?" }
]
for chunk in client . chat ( "openai:gpt-3.5-turbo" , messages ):
print ( chunk , end = "" , flush = True )
print () 디버그 메시지를 표시하려면 vercel_ai.logger.setLevel 으로 전화하십시오.
import vercel_ai
import logging
vercel_ai . logger . setLevel ( logging . INFO )이 프로그램은 GNU GPL V3에 따라 라이센스가 부여됩니다. 모든 코드는 ADING2210에 의해 작성되었습니다.
ading2210/vercel-llm-api: a reverse engineered API wrapper for the Vercel AI Playground
Copyright (C) 2023 ading2210
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.