ParisNeo / ollama_proxy_server

A proxy server for multiple ollama instances with Key security
Apache License 2.0
249 stars 36 forks source link

AttributeError: 'RequestHandler' object has no attribute 'user' #5

Closed changchiyou closed 6 months ago

changchiyou commented 7 months ago

config.ini

[DefaultServer]
url = http://localhost:11434
queue_size = 3

commend

ollama_proxy_server --port 8080 -d

Error Log

Starting server
Running server on port 8080
192.168.110.5 - - [20/Feb/2024 17:02:12] "GET /api/tags HTTP/1.1" - -
192.168.110.5 - - [20/Feb/2024 17:02:12] "GET /api/tags HTTP/1.1" 200 -
192.168.110.5 - - [20/Feb/2024 17:02:15] "GET /api/version HTTP/1.1" - -
192.168.110.5 - - [20/Feb/2024 17:02:15] "GET /api/version HTTP/1.1" 200 -
192.168.110.5 - - [20/Feb/2024 17:02:18] "POST /api/chat HTTP/1.1" - -
----------------------------------------
Exception occurred during processing of request from ('192.168.110.5', 62516)
Traceback (most recent call last):
  File "/home/fvt/miniconda3/envs/llm/lib/python3.11/socketserver.py", line 691, in process_request_thread
    self.finish_request(request, client_address)
  File "/home/fvt/miniconda3/envs/llm/lib/python3.11/socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/home/fvt/miniconda3/envs/llm/lib/python3.11/socketserver.py", line 755, in __init__
    self.handle()
  File "/home/fvt/miniconda3/envs/llm/lib/python3.11/http/server.py", line 431, in handle
    self.handle_one_request()
  File "/home/fvt/miniconda3/envs/llm/lib/python3.11/http/server.py", line 419, in handle_one_request
    method()
  File "/home/fvt/Desktop/Code/ollama_proxy_server/ollama_proxy_server/main.py", line 86, in do_POST
    self.proxy()
  File "/home/fvt/Desktop/Code/ollama_proxy_server/ollama_proxy_server/main.py", line 145, in proxy
    self.add_access_log_entry(event="gen_request", user=self.user, ip_address=client_ip, access="Authorized", server=min_queued_server[0], nb_queued_requests_on_server=que.qsize())
                                                        ^^^^^^^^^
AttributeError: 'RequestHandler' object has no attribute 'user'

My Research

https://github.com/ParisNeo/ollama_proxy_server/blob/c6aee7e67139d6ad04ff164f286335377dd9fbdc/ollama_proxy_server/main.py#L108

The if-logic above is incorrect, because self._validate_user_and_key() would not be execute while the first expression not deactivate_security is not True.

I fix the problem via assign initial value to self.user:

def proxy(self):
+ self.user = "unknown"
  if not deactivate_security and not self._validate_user_and_key():
changchiyou commented 7 months ago

BTW, althought I didn't change any setting of my client open-webui, open-webui changed to chat mode instead of stream mode after I launched ollama_proxy_server.

ParisNeo commented 6 months ago

Thanks alot. Just fixed it.