
เอกสาร : https://declarai.com
ซอร์สโค้ด : https://github.com/vendi-ai/declarai
Declarai เปลี่ยนรหัส Python ของคุณเป็นงาน LLM ช่วยให้คุณสามารถรวม LLM เข้ากับ codebase ที่มีอยู่ได้อย่างง่ายดาย มันทำงานบนหลักการง่าย ๆ : เพียงกำหนดฟังก์ชัน/คลาส Python โดยการใส่คำอธิบายประกอบฟังก์ชั่นนี้ด้วย docStrings และพิมพ์คำแนะนำคุณให้ชุดคำสั่งที่ชัดเจนสำหรับโมเดล AI โดยไม่ต้องใช้ความพยายามเพิ่มเติม
เมื่อคุณประกาศฟังก์ชั่นของคุณแล้ว Declarai จะรวบรวมเอกสารของฟังก์ชั่นและพิมพ์คำใบ้ลงในแบบจำลอง AI อย่างชาญฉลาดเพื่อให้มั่นใจว่าโมเดลเข้าใจสิ่งที่จำเป็น
หลังจากดำเนินการงาน Declarai ดึงการตอบสนองของ AI และแยกวิเคราะห์มันแปลกลับเป็นประเภทผลตอบแทนที่ประกาศของฟังก์ชัน Python ของคุณ สิ่งนี้จะช่วยลดการแยกวิเคราะห์หรือหลังการประมวลผลด้วยตนเองในส่วนของคุณ
Declarai รักษาพื้นเมือง: ที่สำคัญของมัน Declarai เป็นเรื่องเกี่ยวกับการยอมรับการปฏิบัติของงูหลามพื้นเมือง คุณไม่จำเป็นต้องเรียนรู้ไวยากรณ์ใหม่หรือปรับให้เข้ากับกระบวนทัศน์การเข้ารหัสที่แตกต่างกัน เพียงแค่เขียนฟังก์ชั่น Python ตามที่คุณมีอยู่เสมอและให้ Declarai จัดการการรวม 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?" ))
>> > 1การแชท AI ใช้สำหรับการสนทนาซ้ำ ๆ กับโมเดล 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 >หรือผ่านโทเค็นเมื่อเริ่มต้นวัตถุ declarai
import declarai
gpt_35 = declarai . openai ( model = "gpt-3.5-turbo" , openai_token = "<your-openai-key>" ) สร้างฟังก์ชันการทำงานที่ขับเคลื่อนด้วย AI ได้อย่างง่ายดายโดยใช้ @task Decorator เพียงเพิ่มคำแนะนำบางประเภทและเอกสารเล็กน้อยและดู Declarai ทำเวทมนตร์!
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 ครั้งแรกของคุณ!
Declarai มีจุดมุ่งหมายเพื่อส่งเสริมรหัสที่สะอาดและอ่านได้โดยการบังคับใช้การใช้เอกสารและการพิมพ์ รหัสผลลัพธ์สามารถอ่านได้และสามารถบำรุงรักษาได้ง่าย
Python Primitives
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?" ))
>> > 1Python Lists/dicts ฯลฯ ..
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' ]วัตถุที่ซับซ้อนของ Python
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 ประกาศดียิ่งขึ้นด้วยกัน! ตรวจสอบคู่มือการสนับสนุนของเราเพื่อเริ่มต้น