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

Langchain integration #466

Closed
wants to merge 10 commits into from
Closed

Conversation

hrobbins
Copy link
Contributor

@hrobbins hrobbins commented Jul 2, 2023

Trying to keep things simple for this initial conversion to LangChain. The only difference with the original functionality is this version doesn't stream the output from OpenAI, so there is bit of a delay in waiting for the result.

This branch will enable using any LLM, from hugging-face, locally, any LangChain supported LLM service, such as Anthropic/Claude, or pointing it to a Custom LLM.

Copy link
Owner

@AntonOsika AntonOsika left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% we want langchain in here:)

logger.debug(f"Chat completion finished: {messages}")
return messages

def lastMessageContent(self, messages):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python uses snake case

if messages and isinstance(messages, list) and len(messages) > 0:
r = json.dumps(messages_to_dict(messages))
except Exception as e:
logging.warn("Exception serializing messages, returning empty array", e)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exception handling should not exist imo?

@@ -97,15 +98,19 @@ def logs_to_string(steps: List[Step], logs: DB):
chunks = []
for step in steps:
chunks.append(f"--- {step.__name__} ---\n")
messages = json.loads(logs[step.__name__])
chunks.append(format_messages(messages))
# messages = json.loads(logs[step.__name__])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments?

@AntonOsika
Copy link
Owner

Thanks @hrobbins for contributing to improving the repository!

I can see the case for being able to use other language models, but I think we can do that without langchain, and we want to keep it simple. Are there other advantages?

We only merge PRs that use python pep8, doesn't leave comments hanging around etc. So since this is not the focus right now, I will close the PR, but feel free to open it if you are committed to fixing everything and can argue for why we want langchain today.

@AntonOsika AntonOsika closed this Jul 2, 2023
@AntonOsika AntonOsika mentioned this pull request Jul 2, 2023
self.chat = ChatOpenAI(model=self.modelid, temperature=temperature)
except Exception as e:
# ? try a different model
logging.warning(e)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not catch this error – it should raise!

logger.debug(f"Chat completion finished: {messages}")
return messages

def lastMessageContent(self, messages):
m = messages[-1].content
if m:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need if statement here

return m

def serializeMessages(messages):
# dicts = messages_to_dict(history.messages)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

# dicts = messages_to_dict(history.messages)
r = "[]"
try:
if messages and isinstance(messages, list) and len(messages) > 0:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why check?

@AntonOsika
Copy link
Owner

There is a lot of good stuff here so happy to reopen

@AntonOsika AntonOsika reopened this Jul 6, 2023
@AntonOsika
Copy link
Owner

@hrobbins thought more about it and I like many things here

would need to address the comments and make sure streaming is still working before we merge though.

Have you given up on this or are you up for the challenge?

@UmerHA
Copy link
Collaborator

UmerHA commented Jul 7, 2023

@hrobbins if you don't have the time to do it, let me know - id be happy to do it!

need this to finish #431

(cc @AntonOsika)

@hrobbins
Copy link
Contributor Author

hrobbins commented Jul 7, 2023 via email

@UmerHA
Copy link
Collaborator

UmerHA commented Jul 7, 2023

Hey @hrobbins! Sorry, I was too eager 🙈 I had already implemented it before I saw your response.

Here's the branch: https://github.com/UmerHA/gpt-engineer/commits/langchain-integration.

Iiuc, the scope of this PR is to make it work for (i) LangChain models, (ii) HuggingFace models, and (iii) local models. I've done (i), so you could still do (ii) and (iii).

If you want, I can merge my code into yours?
Or should I open a PR instead?

Will do what you decide.

@hrobbins
Copy link
Contributor Author

hrobbins commented Jul 7, 2023 via email

@hrobbins
Copy link
Contributor Author

hrobbins commented Jul 7, 2023

Hey @hrobbins! Sorry, I was too eager 🙈 I had already implemented it before I saw your response.

Here's the branch: https://github.com/UmerHA/gpt-engineer/commits/langchain-integration.

Iiuc, the scope of this PR is to make it work for (i) LangChain models, (ii) HuggingFace models, and (iii) local models. I've done (i), so you could still do (ii) and (iii).

If you want, I can merge my code into yours? Or should I open a PR instead?

Will do what you decide.

Reviewed what you did. Nicely done!

@UmerHA UmerHA mentioned this pull request Jul 7, 2023
@AntonOsika AntonOsika closed this Jul 12, 2023
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.

3 participants