58 lines
1.5 KiB
Text
58 lines
1.5 KiB
Text
from lightbug_http import *
|
|
from lightbug_http.client import Client
|
|
|
|
fn main() raises:
|
|
"""
|
|
Qwen 3 Coder Non-Streaming Example in Mojo
|
|
|
|
NOTE: This is a basic implementation. Streaming is NOT yet supported
|
|
by Lightbug HTTP as of 2025-10-15.
|
|
"""
|
|
|
|
print("Requesting from Qwen 3 Coder...\n")
|
|
|
|
# Create JSON payload
|
|
var payload = String("""
|
|
{
|
|
"model": "hf.co/unsloth/Qwen3-Coder-30B-A3B-Instruct-GGUF:Q4_K_M",
|
|
"messages": [
|
|
{
|
|
"role": "user",
|
|
"content": "Give a Python Fizzbuzz solution in one line of code?"
|
|
}
|
|
],
|
|
"temperature": 0.5,
|
|
"max_tokens": 150,
|
|
"stream": false
|
|
}
|
|
""")
|
|
|
|
# Create HTTP client
|
|
var client = Client()
|
|
|
|
# Parse URI
|
|
var uri = URI.parse_raises("https://qwen.ai.unturf.com/v1/chat/completions")
|
|
|
|
# Create headers
|
|
var headers = Header("Host", "qwen.ai.unturf.com")
|
|
headers.append("Content-Type", "application/json")
|
|
headers.append("Content-Length", String(len(payload)))
|
|
|
|
# Create request
|
|
var request = HTTPRequest(uri, headers)
|
|
request.body = payload.as_bytes()
|
|
|
|
try:
|
|
# Make request
|
|
var response = client.do(request^)
|
|
|
|
# Print response
|
|
print("Status Code:", response.status_code)
|
|
print("\nResponse Body:")
|
|
print(to_string(response.body_raw))
|
|
|
|
print("\nNOTE: Streaming is not yet implemented in Lightbug HTTP.")
|
|
print("This is a non-streaming example only.")
|
|
|
|
except e:
|
|
print("Error:", e)
|