
문서 : https://declarai.com
소스 코드 : https://github.com/vendi-ai/declarai
DeLlarai는 Python 코드를 LLM 작업으로 전환하여 LLM을 기존 코드베이스에 쉽게 통합 할 수 있습니다. 간단한 원칙으로 작동합니다. 파이썬 함수/클래스를 정의하십시오. 이 기능에 docstrings 및 type 힌트로 주석을 달면 추가 노력없이 AI 모델에 대한 명확한 명령 세트를 제공합니다.
기능을 선언 한 후에는 DeLarai가 기능의 문서 및 유형 힌트를 AI 모델의 프롬프트로 지능적으로 컴파일하여 모델이 필요한 것을 정확하게 이해하도록합니다.
작업을 실행 한 후 DeMarai는 AI의 응답을 검색하여 파열 기능의 선언 된 반환 유형으로 다시 번역합니다. 이렇게하면 수동 구문 분석 또는 후 처리가 제거됩니다.
DeLlarai는 그것을 기본적으로 유지합니다. 핵심적으로 DeLlarai는 기본 Python 관행을 수용하는 것입니다. 새로운 구문을 배우거나 다른 코딩 패러다임에 적응할 필요가 없습니다. 당신이 항상 가지고있는 것처럼 Python 기능을 작성하고 DeLlarai가 AI 통합을 완벽하게 처리하도록하십시오.
AI 작업은 모든 비즈니스 로직 또는 변환에 사용됩니다.
import declarai
gpt_35 = declarai . openai ( model = "gpt-3.5-turbo" )
@ gpt_35 . task
def rank_by_severity ( message : str ) -> int :
"""
Rank the severity of the provided message by it's urgency.
Urgency is ranked on a scale of 1-5, with 5 being the most urgent.
:param message: The message to rank
:return: The urgency of the message
"""
rank_by_severity ( message = "The server is down!" )
>> > 5
rank_by_severity ( message = "How was your weekend?" ))
>> > 1AI 채팅은 AI 모델이 이전 메시지와 컨텍스트를 기억할 수있는 AI 모델과의 반복 대화에 사용됩니다.
import declarai
gpt_35 = declarai . openai ( model = "gpt-3.5-turbo" )
@ gpt_35 . experimental . chat
class SQLBot :
"""
You are a sql assistant. You help with SQL related questions
"""
sql_bot = SQLBot ()
sql_bot . send ( "When should I use a LEFT JOIN?" )
> " You should use a LEFT JOIN when you want to return all rows from ....pip install declarai export OPENAI_API_KEY= < your openai token >또는 DeMarai 객체를 초기화 할 때 토큰을 통과하십시오
import declarai
gpt_35 = declarai . openai ( model = "gpt-3.5-turbo" , openai_token = "<your-openai-key>" ) @task 데코레이터를 사용하여 쉽게 AI 구동 기능을 사용하십시오. 유형의 힌트와 약간의 문서를 추가하고 DeMarai가 마법을하는 것을보십시오!
import declarai
gpt_35 = declarai . openai ( model = "gpt-3.5-turbo" )
@ gpt_35 . task
def generate_poem ( title : str ) -> str :
"""
Write a 4 line poem on the provided title
"""
res = generate_poem (
title = "Declarai, the declarative AI framework for LLMs"
)
print ( res )
# Declarai, the AI framework,
# Empowers LLMs with declarative power,
# Efficiently transforming data and knowledge,
# Unlocking insights in every hour.최고의시는 아니지만 이봐! 첫 번째 선언 AI 코드를 작성했습니다!
DeLlarai는 Doc-Strings 및 Typing의 사용을 시행하여 깨끗하고 읽기 쉬운 코드를 홍보하는 것을 목표로합니다. 결과 코드는 읽기 쉽고 쉽게 유지 관리 할 수 있습니다.
파이썬 프리미티브
import declarai
gpt_35 = declarai . openai ( model = "gpt-3.5-turbo" )
@ gpt_35 . task
def rank_by_severity ( message : str ) -> int :
"""
Rank the severity of the provided message by it's urgency.
Urgency is ranked on a scale of 1-5, with 5 being the most urgent.
:param message: The message to rank
:return: The urgency of the message
"""
rank_by_severity ( message = "The server is down!" )
>> > 5
rank_by_severity ( message = "How was your weekend?" ))
>> > 1파이썬 목록/딕트 등 ..
from typing import List
import declarai
gpt_35 = declarai . openai ( model = "gpt-3.5-turbo" )
@ gpt_35 . task
def multi_value_extraction ( text : str ) -> List [ str ]:
"""
Extract the phone numbers from the provided text
:param text: content to extract phone number from
:return: The phone numbers that where identified in the input text
"""
multi_value_extraction (
text = "Hey jenny, n you can call me at 124-3435-132. n "
"you can also reach me at +43-938-243-223"
)
>> > [ '124-3435-132' , '+43-938-243-223' ]파이썬 복합체 객체
from datetime import datetime
import declarai
gpt_35 = declarai . openai ( model = "gpt-3.5-turbo" )
@ gpt_35 . task
def datetime_parser ( raw_date : str ) -> datetime :
"""
Parse the input into a valid datetime string of the format YYYY-mm-ddThh:mm:ss
:param raw_date: The provided raw date
:return: The parsed datetime output
"""
datetime_parser ( raw_date = "Janury 1st 2020" ))
>> > 2020 - 01 - 01 00 : 00 : 00 from pydantic import BaseModel
from typing import List , Dict
import declarai
class Animal ( BaseModel ):
name : str
family : str
leg_count : int
gpt_35 = declarai . openai ( model = "gpt-3.5-turbo" )
@ gpt_35 . task
def suggest_animals ( location : str ) -> Dict [ int , List [ Animal ]]:
"""
Create a list of numbers from 0 to 5
for each number, suggest a list of animals with that number of legs
:param location: The location where the animals can be found
:return: A list of animal leg count and for each count, the corresponding animals
"""
suggest_animals ( location = "jungle" )
>> > {
0 : [
Animal ( name = 'snake' , family = 'reptile' , leg_count = 0 )
],
2 : [
Animal ( name = 'monkey' , family = 'mammal' , leg_count = 2 ),
Animal ( name = 'parrot' , family = 'bird' , leg_count = 2 )
],
4 : [
Animal ( name = 'tiger' , family = 'mammal' , leg_count = 4 ),
Animal ( name = 'elephant' , family = 'mammal' , leg_count = 4 )
]
} import declarai
gpt_35 = declarai . openai ( model = "gpt-3.5-turbo" )
@ gpt_35 . task
def sentiment_classification ( string : str , examples : List [ str , int ]) -> int :
"""
Classify the sentiment of the provided string, based on the provided examples.
The sentiment is ranked on a scale of 1-5, with 5 being the most positive.
{% for example in examples %}
{{ example[0] }} // {{ example[1] }}
{% endfor %}
{{ string }} //
"""
sentiment_classification ( string = "I love this product but there are some annoying bugs" ,
examples = [[ "I love this product" , 5 ], [ "I hate this product" , 1 ]])
>> > 4 import declarai
gpt_35 = declarai . openai ( model = "gpt-3.5-turbo" )
@ gpt_35 . experimental . chat
class CalculatorBot :
"""
You a calculator bot,
given a request, you will return the result of the calculation
"""
def send ( self , message : str ) -> int : ...
calc_bot = CalculatorBot ()
calc_bot . send ( message = "1 + 1" )
>> > 2철저한 소개, 기능 및 모범 사례를 위해 공식 문서 및 초보자 안내서를 살펴보십시오.
선언적인 AI를 더 나은 함께 만들기 위해 우리의 사명에 참여하십시오! 기고 가이드를 확인하여 시작하십시오.