Initial commit with Llama API client and docs

Add Python scripts for Llama API chat clients, endpoint testing, and quick tests. Include documentation (README, CONTRIBUTING, 操作指南), license, and .gitignore. Supports multiple endpoints and models for OpenAI-compatible Llama API usage.
This commit is contained in:
2025-09-19 21:44:02 +08:00
parent 4e28c131d2
commit 8a929936ad
18 changed files with 2073 additions and 0 deletions

54
quick_test.py Normal file
View File

@@ -0,0 +1,54 @@
"""
快速測試內網 Llama API
"""
from openai import OpenAI
# API 設定
API_KEY = "paVrIT+XU1NhwCAOb0X4aYi75QKogK5YNMGvQF1dCyo="
BASE_URL = "http://192.168.0.6:21180/v1" # 使用第一個可用端點
def quick_test():
print("連接到內網 API...")
print(f"端點: {BASE_URL}")
print("-" * 50)
client = OpenAI(
api_key=API_KEY,
base_url=BASE_URL
)
# 測試對話
test_messages = [
"你好,請自我介紹",
"1 + 1 等於多少?",
"今天天氣如何?"
]
for msg in test_messages:
print(f"\n問: {msg}")
try:
response = client.chat.completions.create(
model="gpt-oss-120b",
messages=[
{"role": "user", "content": msg}
],
temperature=0.7,
max_tokens=200
)
answer = response.choices[0].message.content
# 清理可能的思考標記
if "<think>" in answer:
answer = answer.split("</think>")[-1].strip()
if "<|channel|>" in answer:
answer = answer.split("<|message|>")[-1].strip()
print(f"答: {answer}")
except Exception as e:
print(f"錯誤: {str(e)[:100]}")
if __name__ == "__main__":
quick_test()