LLM FOO는 쿵푸의 예술과 대형 언어 모델의 과학을 혼합 한 최첨단 프로젝트입니다. 또는 실제로 이것은 OpenAI 도구 JSON 스키마를 자동으로 만들고 채팅 모델에 대한 결과를 구문 분석하고 결과를 구성하는 것입니다. 그런 다음 하나의 출력 토큰 만 사용하는 Genius Logit_bias 트릭을 사용하는 두 번째 유틸리티 is_statement_true 가 있습니다.
그러나 나는 이것이 현재 출혈 엣지 API가 약간 엉망이기 때문에 더 쉽게 할 수 있다고 생각하기 때문에 이것이 작은 유용한 LLM 헬퍼 기능 세트가되기를 바랍니다.

pip install llmfoo ENV에서 OpenAi_api_key와 gpt-4-1106-preview 모델에 전화 할 수있는 능력이 있어야합니다.
is_statement_true 이해하기 쉬워야합니다. 자연어 진술을하고 기준이나 일반적인 진실성에 대해 확인하십시오. 당신은 부울로 돌아갑니다.
새로 소개 된 pdf2md 기능을 사용하면 PDF 문서를 Markdown 형식으로 변환 할 수 있으므로 LLM 기반 시스템과 쉽게 처리하고 통합 할 수 있습니다. 이 기능은 PDF에서 텍스트와 테이블을 추출하여보다 관리하기 쉬운 형식으로 변환하는 데 특히 유용합니다.
pdftocairo PDF 페이지를 이미지로 변환하려면 시스템에 설치해야합니다. from llmfoo . pdf2md import process_pdf
from pathlib import Path
pdf_path = Path ( "path/to/your/document.pdf" )
output_dir = Path ( "path/to/output/directory" )
# Process the PDF and generate Markdown
markdown_file = process_pdf ( pdf_path , output_dir )이 기능은 PDF의 각 페이지를 처리하여 텍스트, 그림 및 테이블을 추출하여 지정된 출력 디렉토리의 Markdown 파일로 변환합니다.
@tool 주석을 추가하십시오.openai_schema 위해 스키마를 반환합니다 (기계가 한 일에 만족하지 않으면 JSON에서 편집 할 수 있습니다)openai_tool_call 도구 호출을 만들고 채팅 API 메시지 형식에서 결과를 반환합니다.openai_tool_output 도구 호출을 만들고 ASSING API 도구 출력 형식으로 결과를 반환합니다. from time import sleep
from openai import OpenAI
from llmfoo . functions import tool
from llmfoo import is_statement_true
def test_is_statement_true_with_default_criteria ():
assert is_statement_true ( "Earth is a planet." )
assert not is_statement_true ( "1 + 2 = 5" )
def test_is_statement_true_with_own_criteria ():
assert not is_statement_true ( "Temperature outside is -2 degrees celsius" ,
criteria = "Temperature above 0 degrees celsius" )
assert is_statement_true ( "1984 was written by George Orwell" ,
criteria = "George Orwell is the author of 1984" )
def test_is_statement_true_criteria_can_change_truth_value ():
assert is_statement_true ( "Earth is 3rd planet from the Sun" )
assert not is_statement_true ( "Earth is 3rd planet from the Sun" ,
criteria = "Earth is stated to be 5th planet from the Sun" )
@ tool
def adder ( x : int , y : int ) -> int :
return x + y
@ tool
def multiplier ( x : int , y : int ) -> int :
return x * y
client = OpenAI ()
def test_chat_completion_with_adder ():
number1 = 3267182746
number2 = 798472847
messages = [
{
"role" : "user" ,
"content" : f"What is { number1 } + { number2 } ?"
}
]
response = client . chat . completions . create (
model = "gpt-4-1106-preview" ,
messages = messages ,
tools = [ adder . openai_schema ]
)
messages . append ( response . choices [ 0 ]. message )
messages . append ( adder . openai_tool_call ( response . choices [ 0 ]. message . tool_calls [ 0 ]))
response2 = client . chat . completions . create (
model = "gpt-4-1106-preview" ,
messages = messages ,
tools = [ adder . openai_schema ]
)
assert str ( adder ( number1 , number2 )) in response2 . choices [ 0 ]. message . content . replace ( "," , "" )
def test_assistant_with_multiplier ():
number1 = 1238763428176
number2 = 172388743612
assistant = client . beta . assistants . create (
name = "The Calc Machina" ,
instructions = "You are a calculator with a funny pirate accent." ,
tools = [ multiplier . openai_schema ],
model = "gpt-4-1106-preview"
)
thread = client . beta . threads . create ( messages = [
{
"role" : "user" ,
"content" : f"What is { number1 } * { number2 } ?"
}
])
run = client . beta . threads . runs . create (
thread_id = thread . id ,
assistant_id = assistant . id
)
while True :
run_state = client . beta . threads . runs . retrieve (
run_id = run . id ,
thread_id = thread . id ,
)
if run_state . status not in [ 'in_progress' , 'requires_action' ]:
break
if run_state . status == 'requires_action' :
tool_call = run_state . required_action . submit_tool_outputs . tool_calls [ 0 ]
run = client . beta . threads . runs . submit_tool_outputs (
thread_id = thread . id ,
run_id = run . id ,
tool_outputs = [
multiplier . openai_tool_output ( tool_call )
]
)
sleep ( 1 )
sleep ( 0.1 )
messages = client . beta . threads . messages . list ( thread_id = thread . id )
assert str ( multiplier ( number1 , number2 )) in messages . data [ 0 ]. content [ 0 ]. text . value . replace ( "," , "" )기여에 관심이 있으십니까? 이 프로젝트를 개선하는 데 도움을주는 것을 좋아했습니다! 아래의 API는 변경되고 있으며 시스템은 여전히 첫 번째 버전입니다.
이 프로젝트는 MIT 라이센스에 따라 라이센스가 부여됩니다.