Llama Chat and Code Llama are proficient at coding

Uncategorized

< img src ="https://images.idgesg.net/images/article/2023/08/shutterstock_2164664375-100945247-large.jpg?auto=webp&quality=85,70"alt =""> A funny thing occurred when I was playing with Poe, a chatbot aggregator from Quora. I picked the recently launched free almost-open-source Llama 2 70B Chat design from Meta and offered it the prompt “Generate a Python program to scrape a website. Include tests for python.org and infoworld.com.” That’s a shorter variation of a prompt I utilized to check CodeWhisperer, Bard, and Copilot X in June. None of those three designs created a working program.To my utter surprise, Llama 2 70B Chat aced this test: < img alt= "llama code generation 01"width ="1200" height="1102" src="https://images.idgesg.net/images/article/2023/09/llama-code-generation-01-100945713-large.jpg?auto=webp&quality=85,70"/ > IDG

The bot went on to suggest some follow-up questions:

Tell me more. Can you explain how the BeautifulSoup library works for parsing HTML content? Are there any other libraries or tools frequently utilized for web scraping in Python? What are some finest practices for web scraping to guarantee compliance with website terms of service?The created code looked great to me, so I copied it into Visual Studio Code, waited, and ran it. It ran completely:%/ usr/local/bin/ python3/ Users/martinheller/Code/ Llama/scrapesite. py martinheller@Martins-M1-MBP Code %/ usr/local/bin/ python3/ Users/martinheller/Code/ Llama/scrapesite. py Title: Welcome to Python.org Link: #content Link: #python-network Link:/ Link: https://www.python.org/psf/ Link: https://docs.python.org Link: https://pypi.org/ Link:/ jobs/ Link:/ community-landing/ Link: #top Link:/ Link: https://psfmember.org/civicrm/contribute/transact?reset=1&id=2 Link: #site-map Link: # Link: javascript:; Link: javascript:; Link: javascript:; Link: # Link: https://www.facebook.com/pythonlang?fref=ts Link: https://twitter.com/ThePSF Link:/ community/irc/ Link:/ about/ Link:/ about/apps/ Link:/ about/quotes/ Link:/ about/gettingstarted/ Link:/ about/help/ Link: http://brochure.getpython.info/ Link:/ downloads/ Link:/ downloads/ Link:/ downloads/source/ Link:/ downloads/windows/ Link:/ downloads/macos/ Link:/ download/other/ Link: https://docs.python.org/3/license.html Link:/ download/alternatives Link:/ doc/ …

Comparing the Llama-generated code with the CodeWhisperer-generated code, the significant distinction is that Llama used the html.parser model for Beautiful Soup, which worked, while CodeWhisperer used the lxml design, which choked.Llama 2 code description

I also asked Llama 2 70B Chat to describe the very same sample program I had actually given to CodeWhisperer, Bard, and Copilot X. CodeWhisperer doesn’t currently have a chat window, so it does not do code explanations, however Bard did a great job on this job and Copilot X did a good task.

llama code generation 02 IDG IDG

Llama’s description (revealed above) is as excellent, or potentially better, than what Bard generated. I don’t completely understand why Llama dropped in item 12, but I suspect that it may have struck a token limitation, unless I accidentally hit the “stop” button in Poe and didn’t notice.For more about Llama 2 in general, including discussion of its possible copyright infractions and whether it’s open source or not, see “What is Llama 2? Meta’s large language design explained.”Coding with Code Llama A couple of days after I ended up dealing with Llama 2, Meta AI released numerous Code Llama designs. A couple of days after that, at Google Cloud Next 2023, Google revealed that they were hosting Code Llama designs(among lots of others)in the new Vertex AI Design Garden. Furthermore, Perplexity made one of the Code Llama designs offered online, in addition to 3 sizes of Llama 2 Chat.So there were a number of methods to run Code Llama at the time I was writing this article. It’s likely that there will be several more, and several code editor combinations, in the next months.Poe didn’t host any Code Llama models when I first tried it, however during the course of composing this article Quora included Code Llama 7B, 13B, and 34B to Poe’s repertoire. Regrettably, all 3 models provided me the dreaded “Unable to reach Poe “mistake message, which I interpret to imply that the design’s endpoint is busy or not yet connected. The following day, Poe upgraded, and running the Code Llama 34B design worked: IDG As you can see from the screenshot, Code Llama 34B went one much better than Llama 2 and produced programs using both Lovely Soup and Scrapy. Perplexity is website that hosts a Code Llama design, along with numerous other generative AI designs from numerous companies. I tried the Code Llama 34B Instruct model, enhanced for multi-turn code generation, on the Python code-generation task for site scraping:

IDG As far as it went, this wasn’t a bad action. I know that the requests.get()

approach and bs4 with the html.parser engine work for the two sites I suggested for tests, and finding all the links and printing their HREF tags is a good start on processing. An extremely quick code inspection recommended something apparent was missing out on, however: IDG Now this looks more like a command-line utility, but different functionality is now missing out on. I would have preferred a functional kind, however I said” program” instead of” function”when I made the demand, so I’ll offer the model a pass. On the other hand, the program as it stands will report undefined functions when put together. IDG Returning JSON wasn’t actually what I wanted, but for the functions of evaluating the design I have actually most likely gone far enough. Llama 2 and Code Llama on Google Cloud At Google Cloud Next 2023, Google Cloud announced that new additions to Google Cloud Vertex AI’s Model Garden consist of Llama 2 and Code Llama from Meta, and released a Colab Business notebook that lets you release pre-trained Code Llama models with vLLM with the very best available serving throughput.If you need to utilize a Llama 2 or Code Llama design for less than a day, you can dollama code generation 08 so for free, and even run it on a GPU. Usage Colab. If you understand how, it’s easy. If you do not, look for”run code llama on colab “and you

‘ll see a full page of descriptions, including lots of YouTube videos and blog posts on the subject. Keep in mind that while Colab is totally free however time-limited and resource-limited, Colab Business costs cash but isn’t limited.If you want to produce a site for running LLMs, you can use the exact same vLLM library as utilized in the Google Cloud Colab Note pad to set up an API. Ideally, you’ll set it up on a server with a GPU big enough to hold the design you wish to utilize, but that isn’t absolutely needed: You can get by with something like a M1 or M2 Macintosh as long as it has enough RAM to run your design. You can also utilize LangChain for this, at the expense of writing or copying a few lines of code.Running Llama 2 with Ollama If you are utilizing an Arm-based Macintosh as your workstation, you can run Llama designs in your area as a command-line utility. The vital Sharon Machlis discusses how to use Ollama; it’s simple, although if you do not have enough RAM memory for the model it’ll utilize virtual memory (i.e. SSD or, heaven forfend, spinning disk)and run really sluggish.(Linux and Windows support is planned for Ollama.)I checked out Ollama with several models(of the numerous it supports )on my M1 MacBook Pro, which sadly has only 8GB of RAM. I started with my basic Python web-scraping code generation job using Llama 2, apparently one of the smaller models(7B?). The result is comparable to what I received from the Llama 2 70B model operating on Poe, although not as well-structured. Keep in mind that Ollama just downloads the model the very first time it needs it.martinheller@Martins-M1-MBP ~%ollama run llama2 pulling manifest pulling 8daa9615cce3 … 100%|

█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ |(3.8/ 3.8 GB, 51 MB/s )pulling 8c17c2ebb0ea … 100 %| █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ |(7.0 / 7.0 kB, 39 MB/s)pulling 7c23fb36d801 … 100%|█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ |(4.8/ 4.8 kB, 5.0 MB/s) pulling 578a2e81f706 … 100 %| █ █ █ █ █ █ █ █ █ █ █ █ █

█ █ █ █ █ █ █|(95/95 B, 129 kB/s) pulling e35ab70a78c7 … 100%| █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ |(90/90 B, 550 kB/s )pulling 96862bb35d77 … 100%| █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ |(447/447 B, 2.8 MB/s)verifying sha256 absorb composing manifest success >> > Produce a Python program to scrape a site. Include tests for python.org and infoworld.com Sure! Here is an example of how you can use the’requests’and ‘BeautifulSoup’libraries in Python to scrape a site:”‘import demands from bs4 import BeautifulSoup # Example website to scrape url= “https://www.python.org “# Send a demand to the website and get the HTML response response=requests.get (url)# Parse the HTML material using Beautiful Soup soup=BeautifulSoup (response.content,’html.parser’)# Find the particular details you wish to scrape on the site title =soup.find(‘h1′, class _=’main-title’). text print(title)# Output:”Python.org”# Find all the links on the page links=soup.find _ all( ‘a’)for link in links: print(link.get(‘href’))# Output: [/python”,”/ docs”,”/ find out”, and so on.] # Evaluate the code with various sites url2 =”https://www.infoworld.com”response2=requests.get(url2)soup2=BeautifulSoup (response2.content,’html.parser ‘)title2=soup2.find(‘ h1′, class _=’main-title’). text print(title2)# Output:”Infoworld”# Discover all the links on the page links2=soup2.find _ all (‘a’ )for link in links2: print(link.get(‘href’) )# Output: [/news”, “/ functions”,”/ viewpoints”, and so on.]”‘This code sends a demand to the defined site, parses the HTML material using Stunning Soup, and then finds specific info on the page (in this case, the title and all the links). You can modify the ‘url’variable at the top of the script to specify the site you want to scrape. For instance, if you want to scrape the Python documents, you can set’url=”https://www.python.org/doc/` and after that utilize the same code as before to discover the title and links on the page. To evaluate the code with various websites, you can customize the’url2’variable at the top of the script to define a different website. For instance, you can set’url2 =”https://www.infoworld.com “‘to scrape that site, or any other website you wish to evaluate. Note: Make certain you have the necessary authorizations and legal rights to scrape a site. Web scraping can be unlawful sometimes, so make certain to inspect the terms of service for the website you’re scraping and appreciate their rules.With that standard developed, I attempted the very same timely utilizing Code Llama. Once again, I didn’t define the design size, however it looks like it is 7B.martinheller@Martins-M1-MBP ~%ollama run codellama pulling manifest pulling 8268242df6f0 … 100%|█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █|(3.8/ 3.8 GB, 50 MB/s )pulling 2c8743bdc4ad … 100%| █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ |(7.0/ 7.0 kB, 40 MB/s)pulling 38fa20ee7daa … 100 %| █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █|(4.8/ 4.8 kB, 28 MB/s) pulling 578a2e81f706 … 100%| █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ |

(95/95 B, 993 kB/s)pulling 404e21afdc6a … 100%| █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ |(30/30 B, 187 kB/s)pulling 86b68a7bb45d … 100%| █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ |(507/507 B, 4.0 MB/s)confirming sha256 absorb composing manifest success >> > Create a Python program to scrape a site. Consist of tests for python.org and infoworld.com To write a Python program that scrapes a site, you will require to utilize a library such as BeautifulSoup or Scrapy. These libraries allow you to browse and parse the HTML structure of a web page, and extract particular data from it. Here is an example of how you might use BeautifulSoup to scrape the Python website at python.org:”‘import demands from bs4 import BeautifulSoup # Send out a request to the Python website url=’https://www.python.org’ reaction=requests.get(url)# Parse the HTML content using Beautiful Soup soup=BeautifulSoup (response.content,’ html.parser’)# Discover all links on the page links=soup.find _ all(‘a’)# Print each link to the console for link in links: print(link.get(‘href’))”‘To write tests for this program, you can utilize a testing structure such as unittest or pytest. These frameworks permit you to specify test functions that can be run immediately to verify that your code is working properly. Here is an example of how you might write tests using the unittest module:”‘import unittest from bs4 import BeautifulSoup class TestPythonOrg( unittest.TestCase ): def setUp(self ): # Send a demand to the Python website url =’https://www.python.org’ action= requests.get(url)# Parse the HTML content using Beautiful Soup soup =BeautifulSoup(response.content, ‘html.parser’)self.soup= soup def test_title (self): title =self.soup.find (‘title ‘). text self.assertEqual (title,’Python Documents -Python v3.10 ‘)def test_description( self ): description =self.soup.find( ‘meta’, ‘name’:’description’)[‘content’] self.assertIn(‘The main homepage for the Python Programming Language’, description)def tearDown(self ): pass if __ name __==’__ primary __ ‘: unittest.main()” ‘This test program sends out a demand to the Python website, parses the HTML content using Gorgeous Soup, and then runs two separate tests: one that validates that the page title is proper, and another that validates that the page description includes particular keywords. You can run this test program by saving it to a file (e.g.’test_python_org. py ‘), opening a terminal or command prompt, and then running the following command:”‘python test_python_org. py”‘ This will run all of the test works in the program, and print a message suggesting whether each test passed or failed. Source

Leave a Reply

Your email address will not be published. Required fields are marked *