Views
No views yet
1pip uninstall -y torch torchvision torchaudio
2pip install --pre torch torchvision torchaudio \
3 --index-url https://download.pytorch.org/whl/nightly/cu128
4
5export VLLM_VERSION=0.9.0
6pip install https://vllm-wheels.s3.us-west-2.amazonaws.com/nightly/vllm-${VLLM_VERSION}-cp38-abi3-manylinux1_x86_64.whl
7
8pip install hf_transfer
9pip install flashinfer-python
10pip install requests
11
12python3 -m vllm.entrypoints.openai.api_server --host 0.0.0.0 --port 8000 --model miike-ai/Deepseek-R1-Distill-Llama-8B-fp41import requests
2import json
3import sys
4from typing import List, Dict
5
6class ChatSession:
7 def __init__(self, model: str = "miike-ai/Deepseek-R1-Distill-Llama-8B-fp4"):
8 self.url = "http://localhost:8000/v1/chat/completions"
9 self.model = model
10 self.messages: List[Dict[str, str]] = []
11 self.headers = {
12 "Content-Type": "application/json",
13 "Accept": "text/event-stream" # For streaming support
14 }
15
16 def add_message(self, role: str, content: str):
17 self.messages.append({"role": role, "content": content})
18
19 def stream_response(self):
20 data = {
21 "model": self.model,
22 "messages": self.messages,
23 "temperature": 0.7,
24 "stream": True
25 }
26
27 try:
28 with requests.post(self.url, headers=self.headers, json=data, stream=True) as response:
29 if response.status_code != 200:
30 print(f"\nError: API request failed with status code {response.status_code}")
31 print("Response:", response.text)
32 return
33
34 print("\nAssistant: ", end="", flush=True)
35 collected_content = []
36
37 for line in response.iter_lines():
38 if line:
39 try:
40 line = line.decode('utf-8')
41 if line.startswith('data: '):
42 json_str = line[6:] # Remove 'data: ' prefix
43 if json_str.strip() == '[DONE]':
44 break
45 try:
46 chunk = json.loads(json_str)
47 if content := chunk.get('choices', [{}])[0].get('delta', {}).get('content'):
48 print(content, end="", flush=True)
49 collected_content.append(content)
50 except json.JSONDecodeError:
51 continue
52 except Exception as e:
53 print(f"\nError processing chunk: {str(e)}")
54 continue
55
56 print() # New line after response
57 full_content = "".join(collected_content)
58 if full_content:
59 self.add_message("assistant", full_content)
60
61 except requests.exceptions.ConnectionError:
62 print("\nError: Could not connect to the API. Make sure the server is running on localhost:8000")
63 except Exception as e:
64 print(f"\nUnexpected error: {str(e)}")
65
66def run_chat_interface():
67 """
68 Run an interactive chat interface in the terminal
69 """
70 print("\nChat Interface for Local API Testing")
71 print("=====================================")
72 print("Endpoint: http://localhost:8000/v1/chat/completions")
73 print("Type 'exit' or 'quit' to end the chat")
74 print("Type 'clear' to start a new chat session")
75 print("----------------------------------------\n")
76
77 chat = ChatSession()
78
79 while True:
80 try:
81 user_input = input("User: ").strip()
82
83 if not user_input:
84 continue
85
86 if user_input.lower() in ['exit', 'quit']:
87 print("\nGoodbye!")
88 break
89
90 if user_input.lower() == 'clear':
91 chat = ChatSession()
92 print("\nStarted new chat session")
93 continue
94
95 chat.add_message("user", user_input)
96 chat.stream_response()
97
98 except KeyboardInterrupt:
99 print("\n\nGoodbye!")
100 break
101 except EOFError:
102 print("\nGoodbye!")
103 break
104
105if __name__ == "__main__":
106 run_chat_interface()