Format: application/x-python-code
1 o
2
3 `�hk �
4 @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dlm Z d dl
5 mZ d dlm
6 Z
7 e je jd� e �e�Zedd�d d
8 � �Zdefdd
9 �Zddd�Z ddedededededefdd�ZdS )� N)� lru_cache)�AsyncClient)�available_functions)�SYSTEM_PROMPTS)�level� )�maxsizec C s t � S )N)�list_models� r
10 r
11 �>C:\Users\shubh\Videos\agent\agent\modules\llm\ollama_client.py�list_models_cached s r �returnc
12 C st zdd l } | �d�}|�� dd� |�� �dg �D �W S ty9 } zt�dt|�� �� g W Y d }~S d }~ww )Nr zhttp://localhost:11434/api/tagsc S s g | ]}|d �qS )�namer
13 )�.0�modelr
14 r
15 r �
16 <listcomp> s zlist_models.<locals>.<listcomp>�modelszModel listing failed: )�requests�get�raise_for_status�json� Exception�logger�error�str)r �response�er
17 r
18 r r s
19 ��r c
20 C s� dd� } dd� }zdd l }|�d�}|jdkrt�d� W d S W n ty; t�d � | d
21 �r9t�d� |d
22 � Y nw ztjdd
23 gtjtjd� t�d� W d S tyk } zt� d|� �� W Y d }~d S d }~ww )Nc S sF t � t jt j��}|�d| f�dkW d � S 1 sw Y d S )N� localhostr )�socket�AF_INET�SOCK_STREAM�
24 connect_ex)�port�sr
25 r
26 r �is_port_in_use s $�z-ensure_ollama_running.<locals>.is_port_in_usec S s� t �ddg�D ]8}|jdd�D ]/}|jj| kr>z |�� W d S ty= } zt�d| � d|� �� W Y d }~qd }~ww qqd S )N�pidr Zinet)�kindzFailed to kill process on port z: ) �psutilZprocess_iterZnet_connections�laddrr"