Giter Site home page Giter Site logo

Comments (6)

richard-schwab avatar richard-schwab commented on May 22, 2024 1

I currently am using GPT4ALL and Jan which both support api access. I'd love to try this with those.

from plandex.

danenania avatar danenania commented on May 22, 2024

Thanks @michaellatman -- I agree. Adding more flexibility here is a priority.

from plandex.

richard-schwab avatar richard-schwab commented on May 22, 2024

Here is my code to send a prompt to Jan in case that is useful for you to see:

import requests
import json
from datetime import datetime
from tqdm import tqdm

class JanPrompt:
    def __init__(self, ip_address, port, agent_message, command_message):
        self.ip_address = ip_address
        self.port = port
        self.agent_message = agent_message
        self.command_message = command_message
        self.url = f"http://{self.ip_address}:{self.port}/v1/chat/completions"

    def compose_payload(self):
        payload = {
            "messages": [
                {"content": self.agent_message, "role": "system"},
                {"content": self.command_message, "role": "user"}
            ],
            "model": "mistral-ins-7b-q4",
            "stream": True,
            "max_tokens": 2048,
            "stop": ["hello"],
            "frequency_penalty": 0,
            "presence_penalty": 0,
            "temperature": 0.7,
            "top_p": 0.95
        }
        return payload

    def send_prompt(self):
        headers = {'Content-Type': 'application/json'}
        payload = self.compose_payload()
        response = requests.post(self.url, headers=headers, data=json.dumps(payload), stream=True)
        return self.handle_stream(response)

    def handle_stream(self, response):
        final_data = ""
        content_pieces = []
        progress_bar = tqdm(unit="chunk", desc="Receiving data")

        try:
            for line in response.iter_lines():
                if line:
                    decoded_line = line.decode('utf-8')
                    progress_bar.update(1)
                    if decoded_line == "data: [DONE]":
                        break
                    data_json = json.loads(decoded_line.replace("data: ", ""))
                    if "choices" in data_json:
                        for choice in data_json["choices"]:
                            if "delta" in choice and "content" in choice["delta"]:
                                content_pieces.append(choice["delta"]["content"])
        except requests.exceptions.RequestException as e:
            print(f"Request failed: {e}")
        finally:
            progress_bar.close()

        final_data = "".join(content_pieces)
        return final_data

    def save_to_file(self, response_data):
        timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
        filename = f"prompt_result_{timestamp}.md"
        with open(filename, 'w') as file:
            file.write(f"## Agent Message\n\n{self.agent_message}\n\n## Command Message\n\n{self.command_message}\n\n## Response\n\n{response_data}")
        print(f"Saved to {filename}")

    def run(self):
        response_data = self.send_prompt()
        self.save_to_file(response_data)

if __name__ == "__main__":
    ip_address = "localhost"  
    port = 1337  # Replace with the actual port number
    agent_message = "You are a helpful assistant."  
    command_message = "Please give me a recipe for steamed hams."  
    jan_prompt = JanPrompt(ip_address, port, agent_message, command_message)
    jan_prompt.run()

from plandex.

danenania avatar danenania commented on May 22, 2024

Thanks @richard-schwab. Unfortunately as with ollama it looks like Jan doesn't support the tools parameter for function-calling, which Plandex relies on.

from plandex.

mudler avatar mudler commented on May 22, 2024

👍 I was immediately looking into trying this with https://github.com/go-skynet/LocalAI - would be great if we can set up an OPENAI_ENDPOINT

from plandex.

danenania avatar danenania commented on May 22, 2024

Fixed by #46 and just released in server/0.8.3 and cli/0.8.2

from plandex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.