การตั้งค่า custom API ของ ai-hedge-fund
Updated 2026-09-05
เลือก provider ก่อนตั้งค่า endpoint ทำตาม model factory และ registry ปัจจุบัน แล้ว validate data, agent output และ evaluation เป็นคนละ stage
ระบุ application path ปัจจุบัน
สำหรับ application ai-hedge-fund ปัจจุบัน ยืนยัน provider ใน registry ของ model ก่อนตั้งค่า OPENAI_API_BASE ที่ revision fc1bf250 client factory อยู่ใน hedge_fund/llm/client.py และอ่าน registry ที่อยู่ข้างกัน tutorial รุ่นเก่าที่อ้างเฉพาะ src/llm/models.py อธิบาย application path คนละแบบ pin checkout ของคุณและใช้ entrypoint ที่ import factory ปัจจุบัน เริ่มจาก provider preflight ด้านล่าง แล้วทดสอบ project client ก่อนเก็บข้อมูลการเงินสำหรับ research cycle ที่สมบูรณ์
แก้ provider ก่อนตั้ง base URL
make_llm เลือก provider จาก model identifier ที่เลือก OpenAI branch ส่ง OPENAI_API_BASE เข้า ChatOpenAI และอ่าน API key ที่สอดคล้องกัน identifier ที่ไม่รู้จักจะ fallback ไป Anthropic transport ใน source ที่รีวิว ดังนั้นการ export OpenAI base URL อย่างเดียวไม่พอ ยืนยันก่อนว่า endpoint model ID แบบ exact ถูก register ภายใต้ OpenAI ที่นี่ OpenAI ระบุ transport adapter ไม่ได้ certify vendor ของ model ที่อยู่ข้างใต้ อย่าเปลี่ยน global registry entry หากยังไม่เข้าใจทุก workflow ที่ใช้ entry นั้น
| Setting | วัตถุประสงค์ | สิ่งที่ต้องตรวจ |
|---|---|---|
| HEDGE_FUND_LLM_MODEL | เลือก exact model ID | Registry resolve ไปยัง provider ที่ตั้งใจ |
| OPENAI_API_BASE | Override OpenAI transport endpoint | ใช้กับ OpenAI branch |
| OPENAI_API_KEY | Authenticate transport นั้น | พร้อมใช้ใน client process |
| api_models.json | Map model ID กับ provider | Path ปัจจุบันคือ hedge_fund/llm/ |
ตรวจ configuration โดยไม่สร้าง request
ตัวอย่างด้านล่าง fail ก่อนสร้าง client หาก local registry เลือก transport อื่น ตั้ง RESEARCH_MODEL_ID เป็น catalog ID ที่คุณรีวิว application registration แล้ว หากไม่มี ให้เพิ่ม local registry row โดยใช้ display_name, model_name และ provider ที่มีอยู่ และเก็บ entry ที่ไม่เกี่ยวข้องไว้ placeholder นี้ไม่ใช่ model claim ที่รองรับ ส่ง key ผ่าน environment หรือ secret store preflight นี้ตรวจเฉพาะ selection ไม่สามารถยืนยัน network access, account entitlement, structured output หรือคุณภาพงานวิจัย
import os
from hedge_fund.llm.registry import provider_for
model = os.environ["RESEARCH_MODEL_ID"]
if provider_for(model) != "OpenAI":
raise RuntimeError("MODEL_TRANSPORT_MISMATCH")
os.environ["HEDGE_FUND_LLM_MODEL"] = model
os.environ["OPENAI_API_BASE"] = "https://api.apisrouter.com/v1"
assert os.environ["OPENAI_API_KEY"]
# Selection check only; no make_llm() or model request.ไล่ตาม model route ที่เสนอ
model route เริ่มหลัง registry resolution application ยังต้องมี financial data client, universe definition และ research date ที่ชัดเจน gateway key ไม่ใช่ Financial Datasets credential หรือสิทธิ์ในการเผยแพร่ market data ตรวจ company identifier, currency และ timestamp semantics แยกกัน สำหรับบริษัทที่จดทะเบียนหลายตลาด ให้ระบุว่าการวิเคราะห์เกี่ยวกับ issuer, local share class หรือ depositary receipt แยก model-request evidence ออกจาก provider-data evidence เพื่อไม่ให้ financial series ที่หายถูกวินิจฉัยผิดว่าเป็น LLM problem
ตรวจ parsed decision ในฐานะ data
factory ที่รีวิวแล้วห่อ provider client ไว้หลัง method complete(system, user) response text ไม่ใช่ valid research result โดยอัตโนมัติ ตรวจ agent layer ที่ parse JSON จัดการ abstention และรวม output response อาจไม่ว่างแต่ malformed ขัดกันภายใน หรือไม่มี input รองรับ เก็บ raw response ที่ redact แล้วและ parsed object ไว้ใน request record เดียว ตรวจ expected field และ allowed state แทนการ match ประโยคที่ฟังดูมั่นใจ ถือผลลัพธ์ที่หายหรือถูก reject เป็น unavailable ไม่ใช่ neutral signal ที่ไหลเข้า portfolio aggregation แบบเงียบๆ
import os
from hedge_fund.llm.client import make_llm, extract_json
from hedge_fund.llm.registry import provider_for
model = os.environ["HEDGE_FUND_LLM_MODEL"]
assert provider_for(model) == "OpenAI"
client = make_llm(model=model)
result = extract_json(client.complete(
"Return a JSON object with a boolean ready field.",
"Set ready to true.",
))
assert result.get("ready") is True
# This request tests the client and parser, not financial research.ทำ research cycle แรกให้เล็กและรีวิวได้
หลัง authorized client test ให้เลือก issuer เดียวและคำถามที่มีขอบเขต พร้อมหลักฐานที่มี license หรือสาธารณะ ยืนยันว่า tool ที่ต้องใช้คืน company และ period ที่คาดไว้ แล้วเทียบคำอธิบายที่สร้างกับเอกสารต้นฉบับ เก็บ run แรกเป็น read-only และมี human review ที่ชัด ประเมินว่า output อ้าง evidence ฝั่งสนับสนุนและฝั่งตรงข้าม เก็บข้อมูลที่หาย และแยก assumption ออกจาก calculation หรือไม่ ชื่อบทบาทนักวิเคราะห์หรือสไตล์การลงทุนไม่ใช่หลักฐานว่า reasoning ที่สร้างจะทำซ้ำวิธีหรือวิจารณญาณของคนจริง
รักษาความเป็นอิสระของ backtest evidence
application อาจจบ research cycle ได้ ขณะที่ historical evaluation ยังไม่ถูกต้อง ตรวจ publication timestamp, revised data, การเลือกบริษัทที่ยังอยู่ และการใช้ข่าวปัจจุบันใน historical prompt แยก development, validation และ held-out period ก่อน iterate prompt หรือ strategy setting เก็บ benchmark, transaction-cost assumption และ configuration ทุกตัวที่ทดลอง การเลือก prompt ซ้ำจาก test period เดียวกันทำให้ช่วงนั้นกลายเป็น development data รายงาน evaluation ที่ยังไม่ครบตามจริง แทนการเติม results table ด้วย return ตัวอย่างที่อาจถูกเข้าใจว่าเป็นผลวัด
ควบคุม failure และ research spend ทั้งหมด
นับ model call, retry, parsing failure, financial-data charge และ local computation ระดับ job endpoint timeout อาจทำให้ billing ยังไม่ทราบจนกว่าจะกระทบยอด retry transport failure ชั่วคราวภายใต้ budget คงที่ อย่า retry authentication หรือ provider-selection failure เดิมโดยไม่เปลี่ยนอะไร เก็บ failed stage และ sanitized error ไว้รีวิว generic gateway hello response ช่วยแยก transport ได้ แต่เฉพาะ project client ของตัวเองที่ทดสอบ adapter behavior การเปรียบเทียบต้นทุนที่มีประโยชน์ต้องคง source packet, role และ output acceptance criteria ให้เหมือนกันระหว่าง model candidate
หลักฐานและข้อจำกัด
factory และ registry ปัจจุบันถูกรีวิวที่ fc1bf250 เมื่อ September 5, 2026 ตัวอย่างเป็น template ที่มี source รองรับ ไม่มี APIsRouter request หรือ research cycle แบบครบที่รันสำหรับคู่มือนี้ การเรียกก่อนหน้าผ่าน gateway อื่นไม่ยืนยัน integration นี้ เก็บผล client, data tool และ complete artifact แยกกันเมื่อตรวจ environment
คำถามที่พบบ่อย
ทำไม custom ID ของฉันจึงขอ Anthropic key?
ใน factory ที่รีวิว model ID ที่ไม่ register จะ fallback ไป Anthropic ตรวจ provider_for(model) และ registry hedge_fund/llm/api_models.json ปัจจุบันก่อนสร้าง client
OPENAI_API_BASE reroute provider ทุกตัวหรือไม่?
ไม่ มันถูกอ่านใน OpenAI client branch provider อื่นใน registry สร้าง client และอาจใช้ setting คนละแบบ
Registry field ใดสำคัญ?
registry ที่รีวิวอ่าน display_name, model_name และ provider เก็บ endpoint ID แบบ exact และเลือก transport อย่างตั้งใจ
model ใน application menu หมายถึง endpoint เข้าถึงได้หรือไม่?
ไม่ ตรวจ ID ที่แน่นอนและ account access กับ endpoint ที่เลือก application registry กำหนด client selection ไม่ใช่ gateway catalog
หลัง client คืน JSON ควรตรวจอะไร?
ตรวจ financial-data tool, agent output schema, abstention behavior และ final evidence-linked research artifact ด้วย task ที่มีขอบเขต
ใช้ output ส่ง order อัตโนมัติได้หรือไม่?
คู่มือนี้ครอบคลุม research configuration การอนุมัติ order, limit, reconciliation และ operational review เป็นของ execution system ที่ต้อง validate แยก