|
Download API_example.md from Hyungseoky/QQ: direct link, hf CLI and curl.
- Browser
- Download file 7.08 kB
-
https://huggingface.co/Hyungseoky/QQ/resolve/main/API_example.md
- Command line
-
hf download hf://Hyungseoky/QQ/API_example.md
-
curl -L -o API_example.md https://huggingface.co/Hyungseoky/QQ/resolve/main/API_example.md
7.08 kB
| # 3๊ฐ ์ปฌ๋ ์ ํธ์ถํ๋ ๋ฒ (ํ ์คํธ ์ปฌ๋ ์ : page, ์ด๋ฏธ์ง - colqwen, ์ด๋ฏธ์ง - tomoro) | |
| # โ 1. ํ ์คํธ ์ฟผ๋ฆฌ - `page` ์ปฌ๋ ์ ๊ฒ์ | |
| ### ๐ข 1-1. ํํฐ ์์ด ๊ฒ์ | |
| ```bash | |
| curl -X 'POST' \ | |
| ย 'http://10.150.6.47:4275/search/text' \ | |
| ย -H 'accept: application/json' \ | |
| ย -H 'Content-Type: application/json' \ | |
| ย -d '{ | |
| ย ย "query": "๋ฌผ๋ฅ์ ์ฒด ์ ์ ๊ธฐ์ค", | |
| ย ย "top_k": 3 | |
| ย }' | |
| ``` | |
| ### ๐ข 1-2. ๋จ์ผ ํํฐ ์ ์ฉ | |
| ```bash | |
| curl -X 'POST' \ | |
| ย 'http://10.150.6.47:4275/search/text' \ | |
| ย -H 'accept: application/json' \ | |
| ย -H 'Content-Type: application/json' \ | |
| ย -d '{ | |
| ย ย "query": "DSG", | |
| ย ย "top_k": 3, | |
| ย ย "filters": { | |
| ย ย ย "apply_region": "2๊ณต์ฅ" | |
| ย ย } | |
| ย }' | |
| ``` | |
| ### ๐ข 1-3. ๋ค์ค ํํฐ ์ ์ฉ (AND ์กฐ๊ฑด) | |
| ```bash | |
| curl -X 'POST' \ | |
| ย 'http://10.150.6.47:4275/search/text' \ | |
| ย -H 'accept: application/json' \ | |
| ย -H 'Content-Type: application/json' \ | |
| ย -d '{ | |
| ย ย "query": "DSG ์์ ๋ฐ ๊ต์ฒด ์ ์ฐจ", | |
| ย ย "top_k": 3, | |
| ย ย "filters": { | |
| ย ย ย "apply_region": "3๊ณต์ฅ", | |
| ย ย ย "apply_product": "300mm" | |
| ย ย } | |
| ย }' | |
| ``` | |
| --- | |
| # โ 2. ํ ์คํธ ์ฟผ๋ฆฌ - ์ด๋ฏธ์ง ์ปฌ๋ ์ ๊ฒ์ (`Tomoro`) | |
| ### ๐ก 2-1. ํํฐ ์์ด ๊ฒ์ | |
| ```bash | |
| curl -X 'POST' \ | |
| ย 'http://10.150.6.47:4275/search/text/tomoro' \ | |
| ย -H 'accept: application/json' \ | |
| ย -H 'Content-Type: application/json' \ | |
| ย -d '{ | |
| ย ย "query": "๋ฌผ๋ฅ์ ์ฒด ์ ์ ๊ธฐ์ค", | |
| ย ย "top_k": 3 | |
| ย }' | |
| ``` | |
| ### ๐ก 2-2. ๋ค์ค ํํฐ ์ ์ฉ | |
| ```bash | |
| curl -X 'POST' \ | |
| ย 'http://10.150.6.47:4275/search/text/tomoro' \ | |
| ย -H 'accept: application/json' \ | |
| ย -H 'Content-Type: application/json' \ | |
| ย -d '{ | |
| ย ย "query": "์ถํ๊ฒ์ฌ ๊ธฐ์ค", | |
| ย ย "top_k": 3, | |
| ย ย "filters": { | |
| ย ย ย "document_type": "์ง์นจ์", | |
| ย ย ย "apply_product": "์ง์๋ถ๋ฌธ" | |
| ย ย } | |
| ย }' | |
| ``` | |
| --- | |
| ## โ 3. ํ ์คํธ ์ฟผ๋ฆฌ - ์ด๋ฏธ์ง ์ปฌ๋ ์ ๊ฒ์ (`ColQwen3.5`) | |
| ### ๐ข 3-1. ํํฐ ์์ด ๊ฒ์ | |
| ```bash | |
| curl -X 'POST' \ | |
| ย 'http://10.150.6.47:4275/search/text/colqwen35' \ | |
| ย -H 'accept: application/json' \ | |
| ย -H 'Content-Type: application/json' \ | |
| ย -d '{ | |
| ย ย "query": "์์ ์ด์ ์ ์ฐจ", | |
| ย ย "top_k": 3 | |
| ย }' | |
| ``` | |
| ### ๐ข 3-2. ๋ค์ค ํํฐ ์ ์ฉ | |
| ```bash | |
| curl -X 'POST' \ | |
| ย 'http://10.150.6.47:4275/search/text/colqwen35' \ | |
| ย -H 'accept: application/json' \ | |
| ย -H 'Content-Type: application/json' \ | |
| ย -d '{ | |
| ย ย "query": "๋ฌผ๋ฅ์ ์ฒด ์ ์ ๊ธฐ์ค", | |
| ย ย "top_k": 3, | |
| ย ย "filters": { | |
| ย ย ย "apply_region": "์ ์ฌ๊ณตํต", | |
| ย ย ย "dept_name": "Infra๊ตฌ๋งคํ" | |
| ย ย } | |
| ย }' | |
| ``` | |
| # 3. ๋จ์ด ์ฌ์ | |
| # ๋จ์ด์ฌ์ ํธ์ถํ๋ ๋ฒ | |
| ```bash | |
| curl -X POST 'http://10.150.6.47:4276/search/term' \ | |
| -H 'Content-Type: application/json' \ | |
| -d '{ | |
| ย "query": "์์ ๊ณจ๋ ๋ฃฐ", | |
| ย "top_k": 3, | |
| ย "filters": { | |
| ย ย "apply_region": "์ ์ฌ๊ณตํต", | |
| ย ย "document_type": "์ง์นจ์" | |
| ย } | |
| }' | |
| ``` | |
| # 4. ์ต์ข api call | |
| ``` | |
| import requests | |
| import json | |
| # ๐ง ์ค์ | |
| BASE_URL = "http://10.150.6.46:18504" # FastAPI ์๋ฒ ์ฃผ์ | |
| SEARCH_ENDPOINT = f"{BASE_URL}/search" | |
| # ๐ ์ฟผ๋ฆฌ ์์ฒญ ๋ฐ์ดํฐ | |
| payload = { | |
| "query": "TTV ๊ท๊ฒฉ ๊ธฐ์ค", | |
| "top_k": 10, | |
| "image_backend": "colqwen35", # ๋๋ "tomoro" | |
| "alpha_override": None, # ์๋์ผ๋ก query_type ๊ธฐ๋ฐ alpha ์ ์ฉ | |
| "filters": { | |
| # ํ์ ์ ํํฐ ์ถ๊ฐ (์: ๋ถ์, ์ง์ญ, ์ ํ ๋ฑ) | |
| # "dept_name": "ํ์ง๊ด๋ฆฌํ", | |
| # "apply_region": "Korea" | |
| }, | |
| "return_debug": True, # ๋๋ฒ๊ทธ ์ ๋ณด ํฌํจ (๊ฐ๋ฐ์ฉ) | |
| "rerank": True # ๋ฆฌ๋ญ์ปค ์ฌ์ฉ ์ฌ๋ถ (ํ๊ฒฝ ๊ธฐ๋ณธ๊ฐ ๋ฐ๋ฆ) | |
| } | |
| # ๐ ์์ฒญ ๋ณด๋ด๊ธฐ | |
| try: | |
| print("๐ 'TTV ๊ท๊ฒฉ ๊ธฐ์ค' ์ฟผ๋ฆฌ ์ ์ก ์ค...") | |
| response = requests.post( | |
| SEARCH_ENDPOINT, | |
| json=payload, | |
| timeout=60 # ์๋ฒ ์๋ต ๋๊ธฐ ์๊ฐ | |
| ) | |
| # ๐ ์๋ต ํ์ธ | |
| if response.status_code == 200: | |
| result = response.json() | |
| print("\nโ ์ฑ๊ณต! ๊ฒ์ ๊ฒฐ๊ณผ:") | |
| print(json.dumps(result, indent=2, ensure_ascii=False)) | |
| # ๊ฐ๋จํ ์์ 3๊ฐ ๊ฒฐ๊ณผ ์ถ๋ ฅ | |
| print("\n๐ ์์ 3๊ฐ ๊ฒฐ๊ณผ ์์ฝ:") | |
| for i, item in enumerate(result["results"][:3], 1): | |
| rank = item["rank"] | |
| score = item["score"] | |
| rerank_score = item.get("rerank_score") | |
| content = item["content"] or "(๋ด์ฉ ์์)" | |
| print(f" {i}. [Rank:{rank}] (Score: {score:.4f}, Rerank: {rerank_score})") | |
| print(f" {content[:150]}...") | |
| else: | |
| print(f"โ ์์ฒญ ์คํจ: {response.status_code} - {response.text}") | |
| except requests.exceptions.ConnectionError: | |
| print("๐จ ์ฐ๊ฒฐ ์ค๋ฅ: FastAPI ์๋ฒ๊ฐ ์คํ ์ค์ธ์ง ํ์ธํ์ธ์ (uvicorn ์คํ ์ฌ๋ถ)") | |
| except requests.exceptions.Timeout: | |
| print("โฐ ํ์์์: ์๋ฒ ์๋ต์ด ์ง์ฐ๋๊ณ ์์ต๋๋ค.") | |
| except Exception as e: | |
| print(f"๐ฅ ์์์น ๋ชปํ ์ค๋ฅ: {e}") | |
| ``` | |
| # VLM API CALL | |
| ```python | |
| ### H200-2 ์๋ฒ : Qwen3.5-397B-A17B-FP8 | |
| ### ์ด๋ฏธ์ง Input | |
| import requests | |
| import base64 | |
| import mimetypes | |
| ''' | |
| Thinking mode: temperature=0.6, top_p=0.95, top_k=20, min_p=0.0, presence_penalty=0.0, repetition_penalty=1.0 | |
| Instruct (or non-thinking) mode: temperature=0.7, top_p=0.8, top_k=20, min_p=0.0, presence_penalty=1.5, repetition_penalty=1.0 | |
| ''' | |
| def encode_image_to_base64(image_path): | |
| mime_type,_ = mimetypes.guess_type(image_path) | |
| with open(image_path, "rb") as image_file: | |
| base64_encoded = base64.b64encode(image_file.read()).decode("utf-8") | |
| return f"data:{mime_type};base64,{base64_encoded}" | |
| image_path = "./test.png" | |
| image_input = { | |
| "type": "image_url", | |
| "image_url": { | |
| "url": f"{encode_image_to_base64(image_path)}" | |
| } | |
| } | |
| response = requests.post( | |
| "http://10.150.6.160:8000/v1/chat/completions", | |
| json={ | |
| "model": "Qwen3.5-397B-A17B-FP8", | |
| 'messages':[ | |
| {"role":"system", "content":"๋๋ SK์คํธ๋ก ์ AI Assistant์ ๋๋ค."}, | |
| {"role":"user", "content":[ | |
| image_input, | |
| {"type":"text","text":"์ด๋ฏธ์ง OCRํด์ค"} | |
| ] | |
| } | |
| ], | |
| "temperature":0.6, | |
| "top_p":0.95, | |
| "top_k":20, | |
| "min_p":0.0, | |
| "presence_penalty":0.0, | |
| "repetition_penalty":1.0, | |
| } | |
| ) | |
| print(response.json()['choices'][0]['message']['content']) | |
| ### Non-thinking | |
| response = requests.post( | |
| "http://10.150.6.160:8000/v1/chat/completions", | |
| json={ | |
| "model": "Qwen3.5-397B-A17B-FP8", | |
| 'messages':[ | |
| {"role":"system", "content":"๋๋ SK์คํธ๋ก ์ AI Assistant์ ๋๋ค."}, | |
| {"role":"user", "content":[ | |
| {"type":"text","text":"์๋ ํ์ธ์."} | |
| ] | |
| } | |
| ], | |
| "temperature":0.7, | |
| "top_p":0.8, | |
| "top_k":20, | |
| "min_p":0.0, | |
| "presence_penalty":1.5, | |
| "repetition_penalty":1.0, | |
| "chat_template_kwargs": {"enable_thinking": False} ## Thinking(Reasoning) off | |
| } | |
| ) | |
| print(response.json()['choices'][0]['message']['content']) | |
| ``` | |