4 ms·
Every time I look at LangChain it seems like unnecessary abstraction. The value in this example are the prompts.
by Ycros 3y ago
Every time I look at LangChain it seems like unnecessary abstraction. The value in this example are the prompts.
- zby 3y agoSo what are the alternatives to LangChain that the HN crowd uses? I see two contenders: https://github.com/minimaxir/simpleaichat/tree/main/simpleaichat https://github.com/minimaxir/simpleaichat/tree/main/simpleai... https://github.com/griptape-ai/griptape https://github.com/griptape-ai/griptape There is also the llm command line utility that has a very thin underlying library, but which might grow eventually: https://github.com/simonw/llm https://github.com/simonw/llm
- Kiro 3y agoJust code it yourself. Most of the core logic can be replaced with a function that that inserts some parameters into a string template and calls an API.
- bfuller 3y agoThis was the answer for myself as well, pretty cool that we are still at the level where if you have an idea you can build a proof extremely quickly and easily.
- lgrammel 3y agoIf you work with JS or TS, check out this alternative that I've been working on: https://github.com/lgrammel/modelfusion https://github.com/lgrammel/modelfusion It lets you stay in full control over the prompts and control flow while make a lot of things easier and more convenient.
- ilaksh 3y agoimport openai import os openai.api_key = os.environ.get('OPENAI_API_KEY') def completion(messages): response = openai.ChatCompletion.create( model = gpt_model, temperature = 0, messages = messages ) return response['choices'][0]['message']['content'].strip() response = completion([ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Who won the world series in 2020?"} ]) ##### import json import tiktoken import os tokenizer = tiktoken.get_encoding("cl100k_base") class Message: def __init__(self, role, text, length=None): self.role = role self.text = text if length != None: self.length = length else: self.length = self._count_tokens(text) print("New message, token length is",self.length) def _count_tokens(self, text): tokens = tokenizer.encode(text) return len(tokens) class History: def __init__(self, ID=None): self.messages = [] self.ID = ID if self.ID: self._load_from_json() def add(self, role, text): message = Message(role, text) self.messages.append(message) self._save_to_json() def _save_to_json(self): if not self.ID: return data = { "messages": [{"role": m.role, "text": m.text, "length": m.length} for m in self.messages] } self.create_dir_if_not_exists('conversations') with open(f"conversations/{self.ID}.json", "w") as f: json.dump(data, f) def create_dir_if_not_exists(self, directory_path): if not os.path.exists(directory_path): os.makedirs(directory_path) def _load_from_json(self): try: self.create_dir_if_not_exists('conversations') with open(f"conversations/{self.ID}.json", "r") as f: data = json.load(f) self.messages = [Message(m["role"], m["text"]) for m in data["messages"]] except FileNotFoundError: pass def recent_messages(self, max_tokens): recent_messages_reversed = [] total_tokens = 0 for m in reversed(self.messages): if total_tokens + m.length <= max_tokens: recent_messages_reversed.append({ "role": m.role, "content": m.text }) total_tokens += m.length else: break recent_messages = recent_messages_reversed[::-1] return recent_messages
- upwardbound 3y agoIn your loop: for m in reversed(self.messages): if total_tokens + m.length <= max_tokens: recent_messages_reversed.append({ "role": m.role, "content": m.text }) total_tokens += m.length else: break It would be important to change that to not drop system prompts, ever. Otherwise a user can defeat the system prompt simply by providing enough user messages.
- ilaksh 3y agoGood point. The way I use it though is to always add the system prompt to the front after calling that function.
- ploppyploppy 3y agoLMQL - https://lmql.ai/ https://lmql.ai/ Guidance (microsoft) - almost abandoned - https://github.com/microsoft/guidance https://github.com/microsoft/guidance
- syntaxing 3y agoHow do you know guidance is almost abandoned? Did they announce it?
- mohannadcse 3y agoI've been enjoying using (and contributing to) Langroid, it's a new multi-agent LLM framework https://github.com/langroid/langroid https://github.com/langroid/langroid
- ahooda 3y agoI've been actively contributing to Langroid as well. It is easy to use, and the intuitive design allows for the rapid development of LLM applications, streamlining the whole process. Highly recommended for anyone looking into this space!
- deleted 3y ago[deleted]