Quarto Manuscrip Programming


Week 8 and 9 Literate programming
(Communicating Results)1 Default setting of the Quarto Manuscript
1.1 Create the folder
(1) Create an empty folder for Quarto Manuscript and give it a proper name.
(2) Click File-New File-Quarto project-Manuscript project.
(3) Choose the folder we created in step 1.
1.2 Check the main YAML
(1) title:
(2) authors:
(3) bibliography: article citation
1.3 Check the structure of working folder
(1) _quarto.yml: format YAML. This is related to metadata and front matter of the
manuscript. Different formats of output are customized in this ffle.
(2) index.qmd: we write in this main document.
(3) references.bib: your references (which can be downloaded through Google Scholar or
through Zotero).
(4) Rename index.qmd as 0_main_ffle.qmd.
11.4 Generate two additional markdown ffles
Those additional markdown ffles conduct analysis that complement this main ffle.
1_generate_number: remember to put your affffliation here.
2_generate_ffgure: remember to put your affffliation here.
2 Edit YAML section and YAML ffle
2.1 Change the main ffle name in YAML
Please go to _quarto.yml to change the default ffle name to manuscript: article:
0_main_ffle.qmd.
2.2 Python engine
jupyter: python3
2.3 Affffliation
title: Assignment 3
affffliation: University of Auckland
email: xxxx
2.4 Date
date: last-modiffed
2.5 Abstract
abstract: Please put your absract of assignment 3 here. Example: This course will teach
you data science workffow. The course will focus on Python for Finance and reproducible
analytical pipeline.
22.6 keywords
Please put your keywords here
keywords: - Quarto - Manuscript
2.7 Add PDF as one of the output
Go to _quarto.yml
add pdf: default at the next level paramater of format:
comment out jats: default
3 Render the manuscript
3.1 First try
Click the preview button in Vscode.
Additional folders generated: .quarto, _manuscript, _freeze
_freeze: code is not re-evaluated unless their source changes. A corresponding _freeze folder
will be created.
3.2 Click on Word and PDF icon form your folder
Please go to the folder you created at step 1 of Section 1.1
This probably does not work.
Solution 1: Click on Word and PDF icon within Vscode.
Solution 2: manually edit the format parameter within YAML.
3.3 Add number for each section
number-sections: true
34 Python code cells
4.1 Article Notebook: wrong way
If you only run the following code, The article notebook will not appear..
Mylist = [1,2,3,4]
4.2 Article Notebook: correct way
We have to print something or return an object to make Article Notebook show up.
[1, 2, 3, 4]
4.3 Echo code or not
In the code, we can add the following parameter to control whether code will be echoed in the
main text (not Article Notebook):
#| echo: true
More about code cells on the following page: https://quarto.org/docs/reference/cells/cellsjupyter.html
4.4
 Output results or not
#| output: false
Mylist = [1,2,3,4]
Mylist
4.5 Other useful code cells parametrs
#| code-fold: true (Collapse code into an HTML tag)
#| code-line-numbers: true (Include line numbers in code block output)
45 Numbers, ffgures, and tables
5.1 Inline code for numbers
The average gap of eruption is 2.5.
5.2 External embeds: a ffgure
Let us import a ffgure created in another QMD ffle.
Figure 1: Timeline of recent earthquakes on La Palma
Embed: please refer to https://quarto.org/docs/authoring/notebook-embed.html for details
of how to use embeds in Quarto.
5.3 External embeds: speciffc folded line of code
Use the following code to import pandas:
import pandas as pd
import numpy as np
5.4 Display tables
An example adapted from Quarto documentation. Table 1 shows information related to different
 car models.
Table 1: Example
mpg cylinders displacement horsepower weight
18 8 307 130 3504
15 8 350 165 3693
5Table 1: Example
mpg cylinders displacement horsepower weight
18 8 318 150 3436
16 8 304 150 3433
17 8 302 140 3449
15 8 429 198 4341
14 8 454 220 4354
14 8 440 215 4312
14 8 455 225 4425
15 8 390 190 3850
5.5 Add existing figures from a folder
Figure 2: A logo for BUSFIN 711
5.6 Cross References
We can cross-reference figures, tables, equations, sections, etc.
5.7 External embeds: several line of code
This is mainly for the purpose of demonstration:
6 1_generate_number
A (University of Auckland)
import pandas as pd
import numpy as np

 

Python 中集成 Ollama 可以通过使用 `ollama` 官方提供的 Python 客户端库来实现。Ollama 是一个本地运行的大型语言模型(LLM)工具,它支持多种模型,如 Llama 2、Mistral 等,并且可以通过简单的 APIPython 应用程序集成。 ### 安装 Ollama Python 库 首先,需要确保你已经在本地系统上安装了 Ollama。你可以从 [Ollama 官方网站](https://ollama.com/)下载并安装适用于你操作系统的版本。 接下来,安装 Python 客户端库。Ollama 提供了一个官方的 Python 包,可以通过 `pip` 安装: ```bash pip install ollama ``` ### 使用 Ollama Python 库 安装完成后,可以使用 `ollama` 模块来调用 OllamaAPI。以下是一个简单的示例,展示如何使用 Ollama 的 `generate` 方法来生成文本: ```python import ollama # 生成文本 response = ollama.generate(model='llama3', prompt='为什么天空是蓝色的?') # 打印响应 print(response['response']) ``` 在这个例子中,`model` 参数指定了要使用的模型(例如 `llama3`),`prompt` 参数是用户输入的提示词。Ollama 会根据提示词生成相应的文本,并返回一个包含 `response` 字段的字典。 ### 获取模型列表 如果你想查看当前可用的模型,可以使用以下代码: ```python import ollama # 获取模型列表 models = ollama.list() # 打印模型列表 for model in models['models']: print(model['name']) ``` ### 模型对话(Chat) Ollama 还支持更复杂的对话模式,允许你在多轮对话中保持上下文。以下是一个使用 `chat` 方法的示例: ```python import ollama # 开始对话 response = ollama.chat( model='llama3', messages=[ {'role': 'user', 'content': '你好,你能帮我做什么?'}, {'role': 'assistant', 'content': '你好!我可以帮助你回答问题、提供建议,甚至进行简单的创作。有什么我可以帮你的吗?'}, {'role': 'user', 'content': '你能告诉我关于机器学习的基础知识吗?'} ] ) # 打印响应 print(response['message']['content']) ``` 在这个例子中,`messages` 参数是一个包含多个对话记录的列表,每个记录都有一个 `role` 和 `content` 字段。Ollama 会根据这些对话记录生成相应的回复。 ### 错误处理 在实际应用中,建议添加错误处理逻辑,以应对可能出现的网络问题或模型加载失败等情况: ```python import ollama try: response = ollama.generate(model='llama3', prompt='为什么天空是蓝色的?') print(response['response']) except Exception as e: print(f"发生错误: {e}") ``` ### 相关问题
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值