Giter VIP home page Giter VIP logo

langchain-vertexai-gemini-codeadvisor's Introduction

langchain-vertexai-gemini-codeadvisor

A small project to demonstarte usage of LangChain with Google Cloud's VertexAI and Gemini LLM.

This streamlit application accepts a code or a function as an input and generates the following outputs: a detailed description of what the code does, an alternative way to write the code using best practices, and some unit tests to check the code’s functionality.

Prerequisites

Installation

  1. Clone the repository.
  2. Create a python venv https://docs.python.org/3/library/venv.html
  3. Install dependencies

    pip install -r requirements.txt

  4. Start the streamlit app, should open a brower window; if not open manually (the output of below command provides the url)

    streamlit run main.py

How it works

It is wonderful to see how frameworks like LangChain make it easier to work with LLMs, they provide a simplified api which allows to interact with LLMs. Refer to the LangChain docs for more information.

Create an instance of LLM, in this case GCP's VertexAI's gemini-pro

from langchain.llms import VertexAI

llm = VertexAI(model_name="gemini-pro", max_output_tokens=1024)

Create prompt templates

prompt_explain = PromptTemplate.from_template("Explain what the below code does. {entered_code}")

prompt_alternate = PromptTemplate.from_template("Can you rewrite the below function using python best practices? {entered_code}")

prompt_unittests = PromptTemplate.from_template("Create unit test code/cases for the below function. {entered_code}")

Execute the query against the Gemini-pro LLM

  • Get the entered code

entered_code = st.text_area(label="Enter your code here", height=200)

  • Execute query, by providing the code to prompt template and invoking LLM

codeExplanation=llm(prompt_explain.format(entered_code=entered_code))

Refer to the code in

main.py

Usage

  1. Enter a python code/function in the given textarea and press submit
  2. Look for Tabs "Explain", "Alternate", "Unit Tests"

Screen shots of an example usage I tested with

Input

Alt text

Output Explain

Alt text

Output Rewrite suggestion

Alt text

Output Unit Tests

Alt text

langchain-vertexai-gemini-codeadvisor's People

Contributors

laxman-munigala avatar

Stargazers

Kevin Beddingfield avatar

Watchers

 avatar

Forkers

chumpy

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.