Skip to content

Commit

Permalink
add code completion for code llama
Browse files Browse the repository at this point in the history
  • Loading branch information
liltom-eth committed Sep 1, 2023
1 parent 65c963c commit 8bc0090
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions code_completion.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import json
import os
import argparse
import shutil
import requests

import gradio as gr
from dotenv import load_dotenv
from llama2_wrapper import LLAMA2_WRAPPER

FIM_PREFIX = "<PRE> "
Expand Down Expand Up @@ -59,19 +54,6 @@ def main():
load_in_8bit=args.load_in_8bit,
)

theme = gr.themes.Monochrome(
primary_hue="indigo",
secondary_hue="blue",
neutral_hue="slate",
radius_size=gr.themes.sizes.radius_sm,
font=[
gr.themes.GoogleFont("Open Sans"),
"ui-sans-serif",
"system-ui",
"sans-serif",
],
)

def generate(
prompt,
temperature=0.9,
Expand Down Expand Up @@ -108,8 +90,24 @@ def generate(
else:
output = prompt

# for response in stream:
# output += response
# yield output
# return output

previous_token = ""
for response in stream:
output += response
if any([end_token in response for end_token in [EOS_STRING, EOT_STRING]]):
if fim_mode:
output += suffix
yield output
return output
print("output", output)
else:
return output
else:
output += response
previous_token = response
yield output
return output

Expand All @@ -135,7 +133,7 @@ def process_example(args):
<p>This is a demo to complete code with Code Llama. For instruction purposes, please use llama2-webui app.py with CodeLlama-Instruct models. </p>
</div>
"""
with gr.Blocks(theme=theme, analytics_enabled=False) as demo:
with gr.Blocks() as demo:
with gr.Column():
gr.Markdown(description)
with gr.Row():
Expand Down

0 comments on commit 8bc0090

Please sign in to comment.