CoolFace
Apppublic

B2BEnterprise/Python_library_installer

sourceHugging Faceapache-2.0updated 10mo agoView on Hugging Face
0likes
command_generator.py38 linesDownload Raw Back to src
1def llm_lib_installer_v1(imported_libs: str, python_version: str, task: str, api_key: str, libraries: str, model = 'openai/gpt-oss-20b'):2    '''3    imported_libs: Give all the imports made in the current session of the notebook4    api_key: Generated groq api key5    task: The type of task being executed in the session notebook6    model: choose the groq model. Default is GPT OSS7    '''8    from groq import Groq9    import streamlit as st10    client = Groq(api_key=api_key)11    completion = client.chat.completions.create(12        model=model,13        messages=[14            {15                "role": "user",16                "content": f'''Assume we have imported a few libraries in the google colab environment: {imported_libs}. 17                Generate a manual !pip install command for the imported libraries for the task: {task}. Take into account the current libraries: {libraries}18                Make sure there are no conflicts in the library versions even if the libraries are not imported. for instance opencv is dependent on the version of numpy. 19                Suggest a version install for that as well even if it is not imported. In a similar way check all library dependencies. Try to take the latest libraries as far as possible.20                Suggest downgrades only if there is no other choice taking in consideration the python version in the environment is: {python_version}.21                Otherwise try and use the latest versions of the libraries.22                Use the "~=" symbol if needed to allow for backward compatibility between the installed libraries.'''23            }24        ],25        temperature=0,26        max_completion_tokens=8192,27        top_p=1,28        reasoning_effort="medium",29        stream=True,30        stop=None31        )32    33    response_content = ""34 35    for chunk in completion:36        response_content+=chunk.choices[0].delta.content or ""37    38    return response_content