Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a function to docs how to discover all availble models from oll… #502

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

meganoob1337
Copy link

…ama automatically

This is a function i wrote so the Config gets Prefilled with the Ollama Models that are present in the local installation,
you don't need to accept the PR, but maybe you can add it somehow if you want.
Here is my config.py:

"""
This is the Continue configuration file.

See https://continue.dev/docs/customization to for documentation of the available options.
"""
from continuedev.src.continuedev.libs.llm.ollama import Ollama

from continuedev.src.continuedev.core.models import Models
from continuedev.src.continuedev.core.config import CustomCommand, SlashCommand, ContinueConfig
from continuedev.src.continuedev.plugins.context_providers.github import GitHubIssuesContextProvider
from continuedev.src.continuedev.libs.llm.maybe_proxy_openai import MaybeProxyOpenAI

from continuedev.src.continuedev.plugins.steps.open_config import OpenConfigStep
from continuedev.src.continuedev.plugins.steps.clear_history import ClearHistoryStep
from continuedev.src.continuedev.plugins.steps.feedback import FeedbackStep
from continuedev.src.continuedev.plugins.steps.comment_code import CommentCodeStep
from continuedev.src.continuedev.plugins.steps.share_session import ShareSessionStep
from continuedev.src.continuedev.plugins.steps.main import EditHighlightedCodeStep
from continuedev.src.continuedev.plugins.steps.cmd import GenerateShellCommandStep
from continuedev.src.continuedev.plugins.context_providers.search import SearchContextProvider
from continuedev.src.continuedev.plugins.context_providers.diff import DiffContextProvider
from continuedev.src.continuedev.plugins.context_providers.url import URLContextProvider
from continuedev.src.continuedev.plugins.context_providers.terminal import TerminalContextProvider
import requests

def get_model_names(url):
    try:
        # Send a GET request to the URL
        response = requests.get(url)

        # Check if the request was successful (status code 200)
        if response.status_code == 200:
            # Parse the JSON data from the response
            data = response.json()

            # Extract the "name" field from each object in the "models" array
            names = [model["name"] for model in data.get("models", [])]

            return names
        else:
            # Print an error message if the request was not successful
            print(f"Failed to fetch data. Status code: {response.status_code}")
            return []
    except Exception as e:
        # Handle any exceptions that may occur during the request
        print(f"An error occurred: {str(e)}")
        return []

# Function to process model names
def process_model_name(name):
    return Ollama(
			context_length=2048,
			model=name,
			timeout=300,
			prompt_templates={'edit': 'Consider the following code:\n```\n{{{code_to_edit}}}\n```\nEdit the code to perfectly satisfy the following user request:\n{{{user_input}}}\nOutput nothing except for the code. No code block, no English explanation, no start/end tags.'},
			server_url="http://localhost:11434"
		)  # Example: Convert names to uppercase

# Example usage:
url = "http://localhost:11434/api/tags"
model_names = get_model_names(url)

# Check if model_names is empty
if not model_names:
    processed_names = []
else:
    # Use map to apply the process_model_name function to each name in the list
    processed_names = list(map(process_model_name, model_names))

config = ContinueConfig(
    allow_anonymous_telemetry=True,
    models=Models(
		unused=processed_names,
		default=Ollama(
			context_length=2048,
			model="codellama:13b",
			timeout=300,
			prompt_templates={'edit': 'Consider the following code:\n```\n{{{code_to_edit}}}\n```\nEdit the code to perfectly satisfy the following user request:\n{{{user_input}}}\nOutput nothing except for the code. No code block, no English explanation, no start/end tags.'},
			server_url="http://localhost:11434"
		)
	),
    system_message=None,
    temperature=0.5,
    custom_commands=[
        CustomCommand(
            name="test",
            description="Write unit tests for the highlighted code",
            prompt="Write a comprehensive set of unit tests for the selected code. It should setup, run tests that check for correctness including important edge cases, and teardown. Ensure that the tests are complete and sophisticated. Give the tests just as chat output, don't edit any file.",
        )
    ],
    slash_commands=[
        SlashCommand(
            name="edit",
            description="Edit code in the current file or the highlighted code",
            step=EditHighlightedCodeStep,
        ),
        SlashCommand(
            name="config",
            description="Customize Continue - slash commands, LLMs, system message, etc.",
            step=OpenConfigStep,
        ),
        SlashCommand(
            name="comment",
            description="Write comments for the current file or highlighted code",
            step=CommentCodeStep,
        ),
        SlashCommand(
            name="feedback",
            description="Send feedback to improve Continue",
            step=FeedbackStep,
        ),
        SlashCommand(
            name="clear",
            description="Clear step history",
            step=ClearHistoryStep,
        ),
        SlashCommand(
            name="share",
            description="Download and share the session transcript",
            step=ShareSessionStep,
        ),
        SlashCommand(
            name="cmd",
            description="Generate a shell command",
            step=GenerateShellCommandStep,
        ),
    ],
    context_providers=[
        # GitHubIssuesContextProvider(
        #     repo_name="<your github username or organization>/<your repo name>",
        #     auth_token="<your github auth token>"
        # ),
        SearchContextProvider(),
        DiffContextProvider(),
        URLContextProvider(
            preset_urls = [
                # Add any common urls you reference here so they appear in autocomplete
            ]
        ),
        TerminalContextProvider(),
    ],
)

@netlify
Copy link

netlify bot commented Sep 23, 2023

Deploy Preview for continuedev ready!

Name Link
🔨 Latest commit bb7cfae
🔍 Latest deploy log https://app.netlify.com/sites/continuedev/deploys/650ed5547f8091000820a544
😎 Deploy Preview https://deploy-preview-502--continuedev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@sestinj
Copy link
Contributor

sestinj commented Sep 23, 2023

This is awesome! It's nice to see something that couldn't be done if the config file was just .json. I'd actually love to include this in some sort of community plugin collection that we could share in the documentation—so I might refactor the way that this exists in the codebase, but will definitely merge!

@meganoob1337
Copy link
Author

Yeah, I wasn't sure how to integrate it so most people can profit from it, and I don't have the insight into the project to know how to integrate it smartly , but I thought you might benefit from it/ know where to put it , because as a feature it would be really cool ;) so I wanted to share!

@sestinj
Copy link
Contributor

sestinj commented Sep 23, 2023

Totally! I actually think I'll use this myself, will make testing different models much nicer : )

@meganoob1337
Copy link
Author

Yay impact 🤣 thanks for your work!

@sestinj
Copy link
Contributor

sestinj commented Oct 5, 2023

@meganoob1337 we started by posting in the #show-and-tell channel in Discord about this, will probably make this the focal point of community plugins until we get enough to warrant a docs page

And I'm doing a bunch of work on cleaning the config file experience (to get strong typing is one thing), and at that point I'll probably try and get this in the codebase

@ivanfioravanti
Copy link

Wow this is amazing @meganoob1337

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants