เริ่มต้นใช้งาน Eidy API

Eidy API เป็นเครื่องมือสำหรับให้นักพัฒนา (Developer)

ให้สามารถนำ Eidy ไปใช้งานเป็นส่วนหนึ่งของ Feature ของ Application

Request parameter

Parameter
Description
Required

messages

ข้อความสำหรับการใช้งาน LLM โดยมีโครงสร้างดังนี้ { "role" : ["user","assistant"], "content" : "Prompt" }

Yes

model

LLM Model ที่สามารถใช้งานได้ ได้แก่ "eidy"

Yes

max_tokens

จำนวน Token ที่ต้องการให้ LLM ตอบกลับเป็นจำนวนกี่ Tokens ค่าเริ่มต้นคือ 1024 tokens

No

temperature

ตัวเลข (Float) ความหลากหลายของคำตอบ ยิ่งค่าสูง คำตอบจะมีความหลากหลายหรือความสร้างสรรค์มากยิ่งขึ้น ค่าเริ่มต้นคือ 0.7

No

stream

เปิดใช้งานการตอบกลับแบบ Streaming (SSE) ค่าเริ่มต้นคือ False

No

random_seed

ตัวเลข (Integer) สำหรับอ้างอิงการตอบคำถาม ถ้า random_seed ไม่เปลี่ยน คำตอบจะเป็นคำตอบเดิม ค่าเริ่มต้นคือ 2

No

ตัวอย่างการใช้งาน Eidy API ด้วยภาษา Python

Single turn

import requests
import json
URL = 'https://api.eidy.cloud/v1/chat/completions'
EIDY_API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

headers = {'content-type': 'application/json', 'Authorization': 'Bearer '+ EIDY_API_KEY}
message = [{
    'role': 'user',
    'content': 'สวัสดี'
}]
data = {
"messages" : message,
"model" : 'eidy',
"max_tokens" : 1024,
"temperature" : 0.1,
"stream" : False
}
res = requests.post(URL, headers=headers ,data=json.dumps(data))

Response

{
'id': '1719064100.8305922-eidy',
 'choices': [{'finish_reason': 'stop',
   'index': 0,
   'message': {'content': "สวัสดี! I'm Eidy, your medical expert. How can I assist you today?",
    'role': 'assistant'},
   'text': "สวัสดี! I'm Eidy, your medical expert. How can I assist you today?"}],
 'created': 1719064100.8305922,
 'model': 'eidy',
 'object': 'chat.completion',
'usage': {'completion_tokens': 20, 'prompt_tokens': 117, 'total_tokens': 137}
}

Multi turn

import requests
import json
URL = 'https://api.eidy.cloud/v1/chat/completions'
EIDY_API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

headers = {'content-type': 'application/json', 'Authorization': 'Bearer '+ EIDY_API_KEY}
message = [{
    'role': 'user',
    'content': 'สวัสดี'
},
{
    'role': 'assistant',
    'content': 'คุณต้องการให้ช่วยอะไร'
},{
    'role': 'user',
    'content': 'พาราเซตามอลไอบูโพรเฟนต่างกันอย่างไร ?'
}]
data = {
"messages" : message,
"model" : 'eidy',
"max_tokens" : 1024,
"temperature" : 0.1,
"stream" : False
}
res = requests.post(URL, headers=headers ,data=json.dumps(data))

Response

{'id': '1719064264.5749536-eidy',
 'choices': [{'finish_reason': 'stop',
   'index': 0,
   'message': {'content': 'Paracetamol and Ibuprofen are both commonly used over-the-counter pain relievers, but they belong to different classes of medications and have distinct mechanisms of action.\n\nParacetamol, also known as acetaminophen, is an analgesic (pain reliever) and antipyretic (fever reducer). It works by inhibiting the production of prostaglandins in the central nervous system, which are substances involved in the transmission of pain signals and the regulation of body temperature. Paracetamol is typically used for mild to moderate pain relief and to reduce fever. It is generally well-tolerated and has minimal anti-inflammatory effects.\n\nOn the other hand, Ibuprofen is a nonsteroidal anti-inflammatory drug (NSAID). In addition to providing pain relief and reducing fever, it also has anti-inflammatory properties. Ibuprofen works by inhibiting the production of prostaglandins throughout the body, including in the peripheral tissues. This makes it effective for reducing inflammation, swelling, and pain associated with conditions such as arthritis, sprains, and strains.\n\nIn summary, the main difference between Paracetamol and Ibuprofen lies in their mechanism of action and their effects on inflammation. Paracetamol primarily provides pain relief and fever reduction without significant anti-inflammatory effects, while Ibuprofen offers pain relief, fever reduction, and anti-inflammatory properties.\n\nIt is important to note that both medications can have side effects, and it is recommended to follow the recommended dosage and consult a healthcare professional if you have any underlying medical conditions or are taking other medications.',
    'role': 'assistant'},
   'text': 'Paracetamol and Ibuprofen are both commonly used over-the-counter pain relievers, but they belong to different classes of medications and have distinct mechanisms of action.\n\nParacetamol, also known as acetaminophen, is an analgesic (pain reliever) and antipyretic (fever reducer). It works by inhibiting the production of prostaglandins in the central nervous system, which are substances involved in the transmission of pain signals and the regulation of body temperature. Paracetamol is typically used for mild to moderate pain relief and to reduce fever. It is generally well-tolerated and has minimal anti-inflammatory effects.\n\nOn the other hand, Ibuprofen is a nonsteroidal anti-inflammatory drug (NSAID). In addition to providing pain relief and reducing fever, it also has anti-inflammatory properties. Ibuprofen works by inhibiting the production of prostaglandins throughout the body, including in the peripheral tissues. This makes it effective for reducing inflammation, swelling, and pain associated with conditions such as arthritis, sprains, and strains.\n\nIn summary, the main difference between Paracetamol and Ibuprofen lies in their mechanism of action and their effects on inflammation. Paracetamol primarily provides pain relief and fever reduction without significant anti-inflammatory effects, while Ibuprofen offers pain relief, fever reduction, and anti-inflammatory properties.\n\nIt is important to note that both medications can have side effects, and it is recommended to follow the recommended dosage and consult a healthcare professional if you have any underlying medical conditions or are taking other medications.'}],
 'created': 1719064264.5749536,
 'model': 'eidy',
 'object': 'chat.completion',
 'usage': {'completion_tokens': 321,
  'prompt_tokens': 154,
  'total_tokens': 475}}

Last updated